April 27, 2019

C Program To Find the Greatest of Three Numbers

The following is a C Program to find greatest among three numbers on screen after taking input from user. Let's get started.

C Program To Find Greatest of Three Numbers
C Program To Find Greatest of Three Numbers

Overview:


Commands

scanf() function is used to obtain input and printf() function is used to print the string on the screen.
if() statement is used as test function.

Program

#include<stdio.h>
#include<conio.h>
void main()
{
     int a,b,c;
     clrscr();
     printf("Enter values of a,b,c:\n");
     scanf("%d%d%d",&a,&b,&c);
     if(a>b&&a>c)
     {
      printf("%d is greatest",a);
     }
     else if(b>a&&b>c)
     {
      printf("%d is greatest",b);
     }
     else if(c>a&&c>b)
     {
      printf("%d is greatest",c);
     }
     else
     {
 printf("all are equal or any two values are equal");
     }
     getch();
}


Output

Two Cases of Output
Two cases of Output

All programs compiled in this post are compiled in AnDOSBox.

Books I Prefer:






I hope this article was helpful to understand C Program to check greatest among three numbers! Comment below, if you've got any question. Head back soon for another interesting article on C Programming.