Pages

This blog is under construction

Thursday, December 20, 2018

C program to read three values from keyboard and print out the largest & smallest of them without using if statement.(using ternary operator)

#include<stdio.h>
void 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);
((x<y)&&(x<z))?printf("Smallest is x :-- %d\n",x):((y<x)&&(y<z))?printf("Smallest is y :--%d\n",y):printf("Smallest is z :-- %d\n",z);
}



Enter Three Numbers:--                                                                                                                               
12                                                                                                                                                     
5                                                                                                                                                      
40                                                                                                                                               
Largest is z :-- 40 Smallest is y :--5 

No comments:

Post a Comment