C Program to find Greatest number among three

In this tutorial you will learn how to write a program in C to find largest of three numbers.

How our program will behave?

Suppose if someone give 3 numbers as input 12, 15 and 10 then our program should return 15 as a output because 15 is a greatest among three.

C Program to find greatest of three numbers

#include<stdio.h>
#include<conio.h>
void main(){
	int a,b,c;
	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);
	if(a>=b && a>=c)
		printf(" a is greatest");
	if(b>=a && b>=c)
		printf(" b is greatest");
	if(c>=a && c>=b)
		printf("c is greatest");
	getch();
} 

Output 1:

enter the value of a: 23
enter the value of b: 12
enter the value of c: 45
c is greatest

Output 2:

enter the value of a: 12
enter the value of b: 34
enter the value of c: 23
 b is greatest

Explanation of greatest of three numbers in c language

  • This is very simple program to find the greatest number among 3 using C language.
  • There are 3 variables in the above program ‘a’, ‘b’, ‘c’ to take the 3 inputs from the users.
  • And also there are 3 if-else loop for the comparison of the numbers to find greatest one.
  • On the basis of comparison greatest number will be printed.

I hope you understood it.

Leave a Comment