Find Greatest number using Conditional Operator
#include<stdio.h>
void main()
{
int n1,n2,n3;
printf("Enter Numbers (n1 n2 n3) : ");
scanf("%d %d %d",&n1,&n2,&n3);
printf("Greatest= %d",n1>n2?n1>n3?n1:n3:n2>n3?n2:n3);
}
#include<stdio.h>
void main()
{
int n1,n2,n3;
printf("Enter Numbers (n1 n2 n3) : ");
scanf("%d %d %d",&n1,&n2,&n3);
printf("Greatest= %d",n1>n2?n1>n3?n1:n3:n2>n3?n2:n3);
}
Output
Enter Numbers (n1 n2 n3) : 4 9 2
Greatest= 9
Comments
Post a Comment