Skip to main content

Posts

Showing posts with the label examples on ternary operator

C Program To Find Largest/Smallest Of Four Nos. Using Ternary Operator.

22) Sample C Program to find largest of four nos. by using Ternary Operator. # include <stdio.h> # include <conio.h> main( ) { int a, b, c, d, big; clrscr( ); printf("Enter the value of a:"); scanf("%d",&a); printf("Enter the value of b:"); scanf("%d",&b); printf("Enter the value of c:"); scanf("%d",&c); printf("Enter the value of d:”); scanf("%d",&d); big = (a > b)?(a > c)?(a > d)?a:d:(c > d)?c:d:(b > c)?(b > d)?b:d:(c > d)?c:d; printf("Biggest of the given 4 numbers is %d", big); getch(); } 23) Sample C Program to find smallest of four nos. by using Ternary Operator. # include <stdio.h> # include <conio.h> main( ) { int a, b, c, d, small; clrscr( ); printf("Enter the value of a:"); scanf("%d",&a); printf("Enter the value of b:"); scanf("%d",&b); printf(...