Pages

This blog is under construction

Sunday, January 6, 2019

write a c program to read three values from keyboard and print out the largest and smallest of them,using ternary operator

#include <stdio.h>

int main()
{
int x,y,z;
printf("Enter Three Numbers:--\n");
scanf("%d %d %d",&x,&y,&z);
((x>y)&&(x>z))?printf("Largest is x :-- %d",x):((y>x)&&(y>z))?printf("Largest is y :--%d",y):printf("Largest is z :-- %d",z);

printf("\n");

((x<y)&&(x<z))?printf("Smallest is x :-- %d",x):((y<x)&&(y<z))?printf("Smallest is y :--%d",y):printf("Smallest is z :-- %d",z);
}

Output:
Enter Three Numbers:--                                                                                                          
4                                                                                                                                
5                                                                                                                                
7                                                                                                                                
Largest is z :- 7                                                                                                              
Smallest is x :-- 4 

No comments:

Post a Comment