Below are the 4 steps and solutions to find the Largest of Three Numbers in the C Programming language.
See Also: Largest of Three Numbers in C++ Programming
See Also: Java Program to Find Largest of Three Numbers Using Nested IF
See Also: Largest of Three Numbers in C++ Programming
Largest of Three Numbers in C Using Nested if Else
#include <stdio.h>
int main()
{
/*Largest of Three Numbers in C Using Nested if Else */
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;
}
Largest of Three Numbers in C Using If Else Statements
#include <stdio.h>
int main()
{
/*write a program to find Largest of three numbers in c */
double num1, num2, num3;
printf("Enter Three Numbers: \n");
scanf("%lf %lf %lf", &num1, &num2, &num3);
if (num1 > num2 && num1 > num3)
printf("\nLargest Number Is :%lf", num1);
else if (num2 > num3 && num2 > num1)
printf("\nLargest Number Is :%lf", num2);
else if (num1 > num1 && num3 > num2)
printf("\nLargest Number Is :%lf", num1);
else if ((num1 == num2) && (num2 == num3) && (num3 == num1))
printf("\nAll Numbers Are Equal");
}
See Also: Java Program to Find Largest of Three Numbers Using Nested IF
4 Steps Solutions to find the Largest of Three Numbers in C
- Step 1: The very first step is to compare the first number with the second number. If the first number is largest than the second number then we will compare the first number with the third number. If in this case also the first number is the largest then we will print the output that the First number entered by the user is the largest number. Else go to the second condition.
- Step 2: This condition will execute only if the first condition will failed. Compare the Second number with the third number if the second number is the largest number among the Largest of Three Numbers in C. Print the number else execute the ELSE Statements.
- Step 3: If above both conditions are not true that means the largest number is a third number. Below is one more special case for normal IF-ELSE Statements. The fourth step will not be applicable in the NESTED IF-ELSE Case.
- Step 4: This is the last case if all numbers are the same or equal then it will print a message that
- " All INPUT ARE EQUAL ".
0 Comments: