C Program To Find Minimum And Maximum of Three Numbers

Write a C program to find minimum and maximum of three input numbers given by the user.

C Program:

/* Aim: Write a prgram to find minimum and maximum number between three numbers */

#include<stdio.h>
int main()
{
	int i,n1,n2,n3;
	printf("\n Enter any three number:- ");
	scanf("%d%d%d",&n1,&n2,&n3);

// Conditions to check maximum number
	if(n1>n2 && n1>n3)
		printf("\n %d is maximum among (%d,%d,%d) \n",n1,n1,n2,n3);
	else
	{
		if(n2>n3)     
			printf("\n %d is maximum among (%d,%d,%d) \n",n2,n1,n2,n3);
		else
			printf("\n %d is maximum among (%d,%d,%d) \n",n3,n1,n2,n3);
	} 

// Conditions to check minimum number
	if(n1<n2 && n1<n3)
		printf("\n %d is minimum among (%d,%d,%d) \n \n",n1,n1,n2,n3);
	else
	{
		if(n2<n3)     
			printf("\n %d is minimum among (%d,%d,%d) \n \n",n2,n1,n2,n3);
		else
			printf("\n %d is minimum among (%d,%d,%d) \n \n",n3,n1,n2,n3);
	}
}

Output:

 Enter any three number:- 12 14 15

 15 is maximum among (12,14,15) 

 12 is minimum among (12,14,15) 

Comments