Wednesday, October 5, 2011

How do find out max of 3 numbers using conditional/ternary operator?

#include <stdio.h>

main()
{
    int a, b, c, max;
    printf("Enter three numbers : ") ;
    scanf("%d %d %d", &a, &b, &c);
    max = (a > b) ? (a > c ? a : c) : (b > c ? b : c) ;
    printf("\nThe biggest number is : %d", max) ;
}

No comments :