C Program to Find Greatest of Two Numbers

c program for Greatest of two numbers

Find Greatest of Two Numbers

In C programming language, the greatest of two numbers can be identified with the help of IF-ELSE statement. The user is asked to insert two integers. The numbers inserted are then calculated using a set of program to get the correct output. It will find the highest number among them using IF-ELSE Statement and start checking which one is larger to display the largest number.

Example – If the given  numbers are 12 and 9 then greater number is 12

 12, 9= 12>9

Working

  • Step 1: Start
  • Step 2: Insert two integers a and b from user with the help of scanf statement.
  • Step 3: Check if a is bigger in value than b using if statement.
  • Step4: If a is greater, then print a using the printf statement, if the case is vice versa then check whether b is greater than a with the help of elseif statement.
  • Step 5: If b is greater than a, then print b using printf statement, if not then print a and b are equal using printf statement.
  • Step 6: Stop

C code


#include<stdio.h>
int main()
{
    int a,b;
    printf(“Insert two numbers:”);
    scanf("%d %d",&a, &b);
        
    
    if(a > b)
        printf("%d is greatest",a);
    
    
    else if(b > a)
        printf("%d is greatest",b);   
            
    //for both are equal
    else
        printf("%d and %d are equal", a,b);

    return 0;
}

Output

Insert two numbers:3
5
5 is greatest