Q:

C Program To Find Greater Number. Among Given Three Number

Write a C Program for find a greatest number among given three number .ex-you have to given three number ,number may be Integer, Float, Double You Task is to find a Greatest number Input given by User

Logic : To solve this problem we need to compare all three numbers each other .for better explanation we need three number assume that numbers are 17 ,45 ,56
Step 1 : First We Compare 17 to 45 and 56 if it is greatest then we can say that 17 is greatest else we go to next step

Step 2: Then we compare 45 to 56 and 17  if it is greatest then we can say that 45 is greatest else we go to next step
Step 3: Then we compare 56 to 45 and 17  if it is greatest then we can say that 56 is greatest else we go to next step (Special Case)

Step 4: This is the last case if all numbers are same or equal then it will print a message that

" All INPUT ARE EQUAL "

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

``````#include<stdio.h>

int main()
{
double num1, num2, num3;

printf("Enter Three Numbers: \n");
scanf("%lf %lf %lf", &num1, &num2, &num3);

if (num1 > num2 && num1 > num3)
printf("\nGreatest Number Is :%lf",num1);

else if (num2 > num3 && num2 > num1)
printf("\nGreatest Number Is :%lf",num2);

else if (num1 > num1 && num3 > num2)
printf("\nGreatest Number Is :%lf",num1);

else if ((num1==num2) && (num2==num3) && (num3==num1))
printf("\nAll Are Equal");

}``````

Output:

Enter Three Numbers:

555

555

555

All Are Equal

need an explanation for this answer? contact us directly to get an explanation for this answer
need an explanation for this answer? contact us directly to get an explanation for this answer

``````#include <stdio.h>
int main()
{
double num1, num2, num3;

printf("Enter Three Numbers: ");
scanf("%lf %lf %lf", &num1, &num2, &num3);

if (num1>=num2)
{
if(num1>=num3)
printf("%.2lf Is The Largest Number. ", num1);
else
printf("%.2lf Is The Largest Number. ", num3);
}
else
{
if(num2>=num3)
printf("%.2lf Is The Largest Number. ", num2);
else
printf("%.2lf is the largest number.",num3);
}

return 0;

}``````

Output:

Enter Three Numbers: 123.456

456.789

789.12

789.12 is the largest number.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (2)