1) Find maximum of three numbers using if condition
2) Find maximum of three numbers using ternary / conditional operator
#include<stdio.h>
void main()
{
int no1=12, no2=15, no3=30;
if( no1 > no2 )
{
if( no1 > no3 )
{
printf("no1 is largest");
}
else
{
printf("no3 is largest");
}
}
else
{
if( no2 > no3 )
{
printf("no2 is largest");
}
else
{
printf("no3 is largest");
}
}
}
void main()
{
int no1=12, no2=15, no3=30;
if( no1 > no2 )
{
if( no1 > no3 )
{
printf("no1 is largest");
}
else
{
printf("no3 is largest");
}
}
else
{
if( no2 > no3 )
{
printf("no2 is largest");
}
else
{
printf("no3 is largest");
}
}
}
#include<stdio.h>
int main()
{
int no1, no2, no3, max;
printf("Enter No1 : ");
scanf("%d",&no1);
printf("Enter No2 : ");
scanf("%d",&no2);
printf("Enter No3 : ");
scanf("%d",&no3);
max = no1 > no2 ? ( no1 > no3 ? no1 : no3 ) : ( no2 > no3 ? no2 : no3 );
printf("Maximum number is %d",max);
return 0;
}
int main()
{
int no1, no2, no3, max;
printf("Enter No1 : ");
scanf("%d",&no1);
printf("Enter No2 : ");
scanf("%d",&no2);
printf("Enter No3 : ");
scanf("%d",&no3);
max = no1 > no2 ? ( no1 > no3 ? no1 : no3 ) : ( no2 > no3 ? no2 : no3 );
printf("Maximum number is %d",max);
return 0;
}
0 comments :
Post a Comment