larger of two numbers using conditional operator example program in C
Conditional Operator Example Program :
-
#include<stdio.h>
-
int main(void)
-
{
-
int a,b,max;
-
printf(“Enter values for a and b :”);
-
scanf(“%d%d”,&a,&b);
-
max = a>b ? a : b; /*ternary operator*/
-
printf(“Larger of %d and %d is %dn“,a,b,max);
-
return 0;
-
}
Output :
Enter values for a and b : 10 20
Larger of 10 and 20 is 20
Related Programs :