Write a program in C to find the greatest of three numbers.
Code:
#include <stdio.h>
int main()
{
int a,b,c;
printf("Enter 3 integers:\n");
scanf("%d %d %d",&a,&b,&c);
if(a>b){
if(a>c){
printf("%d is the greatest number.",a);
}
else{
printf("%d is the greatest number.",c);
}
}
else{
if(b>c){
printf("%d is the greatest number.",b);
}
else{
printf("%d is the greatest number.",c);
}
}
return 0;
}
Code:
#include <stdio.h>
int main()
{
int a,b,c;
printf("Enter 3 integers:\n");
scanf("%d %d %d",&a,&b,&c);
if(a>b){
if(a>c){
printf("%d is the greatest number.",a);
}
else{
printf("%d is the greatest number.",c);
}
}
else{
if(b>c){
printf("%d is the greatest number.",b);
}
else{
printf("%d is the greatest number.",c);
}
}
return 0;
}
No comments:
Post a Comment