C Program to Find Maximum of Three Numbers

C Program to Find Maximum of Three Numbers

Write C Program to Find a Maximum of Three Numbers.

//WAP to find the largest of the 3 numbers

#include <stdio.h>

int main()
{
	int n1, n2, n3;

	printf("Enter the number 1 :--> ");
	scanf("%d", &n1);

	printf("Enter the number 2 :--> ");
	scanf("%d", &n2);

	printf("Enter the number 3 :--> ");
	scanf("%d", &n3);

	if(n1 > n2)
	{
		if(n1 > n3)
		{
			printf("\nThe largest number among %d ,%d ,%d  is %d", n1, n2, n3, n1);
		}
		else if(n3 > n1)
		{
			printf("\nThe largest number among %d ,%d ,%d  is %d", n1, n2, n3, n3);
		}

	}
	if(n2 > n1)
	{
		if(n2 > n3)
		{
			printf("\nThe largest number among <%d ,%d ,%d> is %d", n1, n2, n3, n2);
		}
		else if(n3 > n2)
		{
			printf("\nThe largest number among <%d ,%d ,%d> is %d", n1, n2, n3, n3);
		}
	}

	return 0;
}

Output:

Run 1:
Enter the number1 :--> 89
Enter the number2 :--> 56
Enter the number3 :--> 98

The largest number among <89 ,56 ,98> is 98


Run 2:
Enter the number1 :--> 98
Enter the number2 :--> 56
Enter the number3 :--> 12

The largest number among <98 ,56 ,12> is 98



Run 3:
Enter the number1 :--> 98
Enter the number2 :--> 5656
Enter the number3 :--> 56

The largest number among <98 ,5656 ,56>  is 5656