Translate

Friday, January 10, 2014

Write a program to find the greatest of three numbers

Program:

# include int main(){
int a, b, c;
printf("En ter a,b,c: \n");
scanf("%d %d %d",&a,&b,&c);
if (a>b&&a>c){
printf("a is Greater than b and c");
}
else if (b>a&&b>c){
printf("b is Greater than a and c");
}
else if (c>a&&c>b){
printf("c is Greater than a and b");
}
else{
printf("al l are equal or any two values are equal");
}
return 0;
}
Output:
Enter a,b,c: 3 5 8
c is Greater than a and b
Explanatio n with examples:
Consider three numbers a=5,b=4,c= 8
if(a>b&&a>c) then a is greater than b and c
now check this condition for the three numbers 5,4,8 i.e.
if(5>4&&5>8) /* 5>4 is true but 5>8 fails */
so the control shifts to else if condition
else if(b>a&&b>c) then b is greater than a and c
now checking this condition for 5,4,8 i.e.
else if(4>5&&4>8) / * both the conditions fail */
now the control shifts to the next else if condition
else if(c>a&&c>b) then c is greater than a and b
now checking this condition for 5,4,8 i.e.
else if(8>5&&8>4) / * both conditions are satisfied */
Thus c is greater than a and b.

No comments:

Post a Comment

ग़ज़ल

rizw4nkh4n *ख़ुलूस-ए-दिल = purity of heart *एहतराम = आदर, सम्मान *मिज़ाजपुरसी = हाल-चाल पूछना *बाम = घर में सबसे ऊपर का कोठा और छत *इक़राम =...