c program to find greatest of three numbers
Code:
#include <stdio.h>
int main()
{
int a,b,c;
printf("Enter 1st Number:");
scanf("%d",&a);
printf("Enter 2nd Number:");
scanf("%d",&b);
printf("Enter 3rd Number:");
scanf("%d",&c);
if(a>b)
{
if(a>c)
{
printf("%d is greatest",a);
}
else
{
printf("%d is greatest",c);
}
}
else
{
if(b>c)
{
printf("%d is greatest",b);
}
else
{
printf("%d is greatest",c);
}
}
return 0;
}
Sample Input and Output:
Enter 1st Number:4
Enter 2nd Number:5
Enter 3rd Number:1
5 is greatest
If you any have doubt,suggestion regarding this post or website then feel free to share with us.
If you have learned something new from this post then share this post with your family and
friends.
friends.
Happy Learning :)😎
Tags:
Program
Can you do this without using nested if ? :-)
ReplyDeleteYes by using logical operator
ReplyDeleteNice article .....
ReplyDeleteLearn more C programming examples from basics.....
Learn C with examples
Basic C programming examples