maximum out of 4 integer c++ code code example

Example: maximum out of 4 numbers c++ code

Source Code:

#include<stdio.h>
#include<conio.h>
void main()
{
	int a,b,c,d;
	clrscr();
	printf("Enter the value of a:");
	scanf("%d",&a);
	printf("Enter the value of b:");
	scanf("%d",&b);
	printf("Enter the value of c:");
	scanf("%d",&c);
	printf("Enter the value of d:");
	scanf("%d",&d);

	if(a>b)
	{
		if(a>c)
		{
			if(a>d)
			{
				printf("a is maximum”);
			}
			else
			{
				printf("d is maximum");
			}
		}
		else
		{
			if(c>d)
			{
				printf("c is maximum ");
			}
			else
			{
				printf("d is maximum ");
			}
		}
	}
	else
	{
		if(b>c)
		{
			if(b>d)
			{
				printf("b is maximum");
			}
			else
			{
				printf("d is maximum");
			}
		}

		else
		{
			if(c>d)
			{
				printf("c is maximum ");
			}
			else
			{
				printf("d is maximum ");
			}
		}
	}
	getch();
}

Output:

Enter the value of a: 10
Enter the value of b: 20
Enter the value of c: 30
Enter the value of d: 40

D is maximum.

Enter the value of a: 40
Enter the value of b: 30
Enter the value of c: 20
Enter the value of d: 10

A is maximum.

Tags:

Misc Example