Advertisement
Shailrshah

Largest Number using Ternary Operator

Apr 18th, 2013
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.34 KB | None | 0 0
  1. \\Ternary Operator
  2. #include <stdio.h>
  3. int main()
  4. {
  5.     float n1,n2,n3,large;
  6.     printf("Enter 3 numbers.\n");
  7.     scanf("%f%f%f",&n1,&n2,&n3);
  8.     large = n1 > n2 ? (n1 > n3 ? n1 : n3) : (n2 > n3 ? n2 : n3);
  9.     printf("The largest number is %.2f",large);
  10.     return 0;
  11. }
  12. \\Output
  13. \\Enter 3 numbers.
  14. \\3.14
  15. \\3.22
  16. \\6.76
  17. \\The largest number is 6.76
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement