to find the biggest and smallest of three numbers

Here is an optimized program to find the largest and smallest among three entered numbers.

Logic : The entered three numbers N1, N2, N3 are compared in such an order, where the first comparison checks if  N1  largest. If so, prints it out and exists; if not so, it omits N1 from further comparison and checks with N2 and N3 only. The same logic but with complement operator, the program finds the least among the three.

The program needs to include the standard IO library, “stdio.h”

#include<stdio.h>
void main()
{
int n1, n2, n3;
clrscr();
printf(“\n\n\t ENTER THREE NUMBERS A,B,C…(separated by commas): “);
scanf(“%d,%d,%d”, &n1, &n2, &n3);
printf(“\n\n\t THE BIGGEST NUMBER IS…: “);
if( (n1 > n2) && (n1 > n3) )
printf(“%d”, n1);
else if(n2 > n3)
printf(“%d”, n2);
else
printf(“%d”, n3);
printf(“\n\n\t THE SMALlEST NMBER IS…: “);
if( (n1 < n2) && (n1 < n3) )
printf(“%d”, n1);
else if(n2 < n3)
printf(“%d”, n2);
else
printf(“%d”,n3);
getch();
}

Download exe and source code here.

Editorial Team
Editorial Team

We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in