C program to find greatest of 3 numbers

If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

#include<stdio.h>
main()
{
 int n1,n2,n3;
 printf("Enter 3 numbers to find greatest among them\n");
 scanf("%d%d%d",&n1,&n2,&n3);
 if(n1>n2)
 {
  if(n1>n3)
   printf("%d is greater than %d and %d",n1,n2,n3);
  else
   printf("%d is greater than %d and %d",n3,n1,n2);
 }
 else
 {
  if(n2>n3)
  printf("%d is greater than %d and %d",n2,n1,n3);
  else
  printf("%d is greater than %d and %d",n3,n1,n2);
 }
}

OUTPUT:

Enter 3 numbers to find greatest among them
8 25 11
25 is greater than 8 and 11

 

You may also like...

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.