Find the maximum of three numbers using conditional operator in C
Program:
#include <stdio.h>
int main() {
int a, b, c, max;
// Input three numbers
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
// Using conditional (ternary) operator
max = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
// Output result
printf("Maximum number is: %d\n", max);
return 0;
}
Output:
Comments
Post a Comment