In the previous blog we saw how to find even or odd number. Now, we will see how to find the greatest number among the given 3 numbers.

Conditional Statements:-

If condition:-

The if statement is used to examine a given condition and perform actions based on whether or not that condition is true. It's most commonly utilized in scenarios where we need to perform many operations for various situations. The if statement's syntax is seen below.

if(expression)

{

}

If-Else Condition:-

For a single condition, the if-else statement is used to conduct two operations. It's an enhancement to the if statement that allows us to conduct two different operations, one for the condition's correctness and the other for the condition's incorrectness. It is important to note that the if and else blocks cannot be run at the same time. The syntax is seen below.

if(expression)

{

}

else

{

}

If-Else If-Else Condition:-

If-else-if is an expansion of the if-else statement. It is utilized in situations where several cases must be executed for various conditions. If one of the conditions in an if-else-if ladder statement is true, the statements in the if block will be executed; if another condition is true, the statements in the else-if block will be executed; and finally, if none of the conditions are true, the statements in the else block will be executed.

if(expression)

{

}

else

{

}

Algorithm:-

1. Start

2. Get the three inputs num1, num2, num3 by using scanf statement & using the format specifier  "%d" as input 

3. Check if num1 is greater than num2 and num3 if yes print the num1

4. Else if num2 is greater  than num1 and num3 print the num2

5. If both the condition fails print the num3

6. End

Note:

          <  lesser than   

          > greater than 

          ==  equal to

Program:

#include <stdio.h>
int main()
{
int num1,num2,num3;
printf("Enter the number 1,2,3");
scanf("%d %d %d",&num1,&num2,&num3);
if(num1>num2 && num1>num3)
{
    printf("%d", num1);
}
else if(num2>num1 && num2>num3)
{
    printf("%d", num2);
}
else
{
printf("%d", num3);
}

}


Output :-

1. Program screenshot:-




2. Output screenshot:-




In next blog, we will see how to print the number from 1 to N using a for loop .