C Program to Find Total of Even Integers

C Program to Find Greatest of Three Numbers

In this tutorial, we have shared a program that compares Program to find greatest of 3 numbers. The main objective is to study about decision statements such as’ if else’ statement that allow us to choose to execute one sequence of instructions over one or more others depending on certain circumstances.

If the Boolean expression evaluates to true, then the if block will be executed, otherwise, the else block will be executed. C programming language assumes any non-zero and non-null values as true, and if it is either zero or null, then it is assumed as false value.

C Program to Find Greatest of Three Numbers

The if else ladder statement in C programming language is used to test set of conditions in sequence. An if condition is tested only when all previous if conditions in if-else ladder is false. If any of the conditional expression evaluates to true, then it will execute the corresponding code block and exits whole if-else ladder.

How Syntax Looks?

if(condition_expression_One) {
statement1;
} else if (condition_expression_Two) {
statement2;
} else if (condition_expression_Three) {
statement3;
} else {
statement4;
}

Step 1 : First of all condition_expression_One is tested and if it is true then statement 1 will be executed and control comes out out of whole if else ladder.

Step 2: If condition_expression_One is false then only condition_expression_Two is tested. Control will keep on flowing downward, If none of the conditional expression is true.

Step 3: The last else is the default block of code which will gets executed if none of the conditional expression is true.


To Save program in a file, Compile program, debug errors, Execute or Run program with necessary inputs. Verify the outputs obtained.

/*Program to find greatest among 3 numbers*/
void main()
{
       int a,b,c;
       clrscr();
       printf("enter the values of a,b and c");
       scanf("%d%d%d",&a,&b,&c);
if(a>b && a>c)
       printf("%d is greatest of %d %d %d", a,a,b,c);
else
       if(b>c)
       printf("%d is greatest of %d %d %d",b,a,b,c);
else
       printf("%d is gratest of %d %d %d",c,a,b,c);
getch();
}

Output:

Enter the values of a,b and c
10
30
20
30 is greatest of 10 30 20

Let me know if you find any difficulty in understanding this C Program to Find Greatest of Three Numbers with example and I would be glad to explain it further.

Online Training Tutorials