27/02/2023

Largest of Three Numbers in C Using Nested if Else

Write the Largest of Three Numbers in C Using Nested if Else. You have to enter the three numbers, the number may be Integer, Float, or Double You Task is to find the Largest of Three Numbers. The input was given by the User. To solve this problem we need to compare all three numbers to each other .for a better explanation we need three numbers to assume that numbers are 17, 45, and 56.

Largest of Three Numbers in C Using Nested if Else

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

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 ".

Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: