Program to find the largest of three numbers - C Language
Learn by Programming.
If you are having a doubt in any specific line do comment below.
The following programs are one of the ways to find the largest of three numbers.
Please comment your views about the program. We will improvise it for future use.
Method 1:
#include <stdio.h>
int main(){
int a, b, c;
printf("Enter a,b,c: ");
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("all are equal or any two values are equal");
}
return 0;
}
Method 2:
#include <stdio.h>
#include <conio.h>
int main()
{
int a, b, c;
printf("Enter first number ");
scanf("%d",&a);
printf("\nEnter second number ");
scanf("%d",&b);
printf("\nEnter third number ");
scanf("%d",&c);
if(a>b && a>c)
printf("\n%d is the greatest number ",a);
else if(b>c)
printf("\n%d is the greatest number ",b);
else
printf("\n%d is the greatest number ",c);
getch();
}
-Happy Coding.
Share with your Friends
Your suggestion and views will be valuable for future use.
If you find difficult are if you want any other ways of this program do comment it out we will reply back to you with that.
If it is useful do share your with your friends.If you are having a doubt in any specific line do comment below.
Comments
Post a Comment