I am going to explain how to find largest among three number by implementing ternary Operator.
void main()
{
int largest,first,second,third;
clrscr();
printf("Enter First number::");
scanf("%d",&first);
printf("Enter Second number::");
scanf("%d",&second);
printf("Enter Third number::");
scanf("%d",&third);
largest = first > second ? (first > third ? first : third): (second > third ? second : third);
printf("largest number is::%d",largest);
getch();
}
void main()
{
int largest,first,second,third;
clrscr();
printf("Enter First number::");
scanf("%d",&first);
printf("Enter Second number::");
scanf("%d",&second);
printf("Enter Third number::");
scanf("%d",&third);
largest = first > second ? (first > third ? first : third): (second > third ? second : third);
printf("largest number is::%d",largest);
getch();
}
No comments:
Post a Comment