C Program for Number Comparison
1.write a program to perform following operation through enter user choice-
for finding greatest no in given 2 number
for finding greatest no in given 3 number
for finding greatest no in given 4 number
in this program we use( do while loop , switch case and if else condition
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,ch;
clrscr();
do
{
printf("\n1 for finding greatest no in 2 no");
printf("\n2 for finding greatest no in 3 no");
printf("\n3 for finding greatest no in 4 no");
printf("\n0 for exit");
scanf("%d",&ch);
if(ch >= 1 && ch <= 3)
{
printf("enter first no");
scanf(" %d " ,&a);
printf("enter second no");
scanf(" %d " , &b);
if(ch >= 2)
{
printf("enter third no");
scanf(" %d " ,&c);
if(ch == 3)
{
printf("enter fourth no");
scanf(" %d " ,&d);
}
}
}
switch(ch)
{
case 1:
if( a == b )
{
printf("these are equal value");
}
-
else if( a > b )
{
printf("%d is greater than %d ", a, b);
}
else
{
printf("%d is greater than %d", b, a);
}
break;
case 2:
if(a > b && a > c)
printf("%d is greater than %d and %d" , a, b , c);
else if( b> c)
printf("%d is greater than %d and %d", b, c, a);
else
printf("%d is greater than %d and %d", c, a, b);
break;
case 3:
if(a > b && a > c && a > d)
printf("%d is greater than %d , %d and %d", a, b, c, d);
else if(b > c && b > d)
printf("%d is greater than %d, %d and %d", b, c, d, a);
else if( c > d )
printf("%d is greater than %d, %d and %d", c, d, a, b);
else
printf("%d is greater than %d, %d and %d", d, a, b, c);
break;
case 0:
printf("oops! you press wrong key");
break;
default:
printf("wrong choice");
}
}
while( ch != 0 );
getch();
}
No comments:
Post a Comment