Please login

Prime

Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime

Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

C Program to Find Greatest of Two Numbers

Greatest of two numbers in C programming (2)

Find Greatest of Two Numbers

In C programming language, the greatest of 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 no1 and no2 from user with the help of scanf statement.
  • Step 3: Check if the no1 is bigger in value than no2 using if statement.
  • Step4: If no1 is greater, then print no1 using the printf statement, if the case is vice versa then check whether no2 is greater than no1 with the help of elseif statement.
  • Step 5: If no2 is greater than no1, then print no2 using printf statement, if not then print no1 and no2 are equal using printf statement.
  • Step 6: Stop

C Code

    #include<stdio.h>
    int main()
    {
    int no1, no2;
    printf(“Insert two numbers:”);
    scanf(“%d %d”,&no1, &no2);
        
    //Condition to check which of the two number is greater
    //it will compare of number where number 1 is greater
    if(no1 > no2)
        printf(“%d is greatest”,no1);
    
    //where number 2 is greater
    else if(no2 > no1)
        printf(“%d is greatest”,no2);   
            
    //for both are equal
    else
        printf(“%d and %d are equal”, no1, no2);

    return 0;
    }
 
Output
 
Insert Two Numbers : 5
6
6 is the Greatest