C Program to Find the Largest Number Among Three Numbers

C program to find largest number among three number

Find Greatest of Three Numbers

In this article we will see a  C program to Find the Largest Number Among Three Numbers. The C program to find the greatest of three numbers requires the user to insert three integers. Flow chart is also used in C programming to find the greatest number among three integers inserted by the user. A simple if-else block is used to identify the greatest number. We will use if else ladder to get to answer. Below is detailed description of C program to find the largest number among three numbers.

Problem Description

C program to find the greatest of three numbers require the user to insert three integers. Flow chart is also used in C programming to find the greatest number among three integers inserted by the user. A simple if-else block is used to identify the greatest number. The program will ask the user to insert three integer variables. And on the basis of the inserted number, the program will equate and exhibit the greatest number as an output. This program uses no1, no2 & no3 as three integer variables that are represented number1, number2 and number3 respectively in the program.

C program to find largest number among three number

Working

  • Step 1: Start
  • Step 2: Take three integer values from user.
  • Step 3: If no1 is greater than no2 and no3, printf “Number1 is greatest”.
  • Step 4: If no2 is greater than no1 and no3, printf “Number2 is greatest”.
  • Step 5: If both the conditions are false, then printf “Number3 is greatest”.
  • Step 6: Stop

C code

#include<stdio.h>
int main()
{
    //Declare three variables to store numbers
    int no1,no2,no3;
    
    //Prompt user to insert first number
    printf("\nInsert value of first number: ");
    scanf("%d", &no1);
    
    //Prompt user to insert second number
    printf("\nInsert value of second number: ");
    scanf("%d", &no2);
 
    //Prompt user to insert third number
    printf("\nInsert value of third number: ");
    scanf("%d", &no3);
    
    //for check of number 1 is greater   
    if((no1 > no2) && (no1 > no3))
        printf("\n %d is greatest",no1);

    //weather number 2 is grater 
    else if((no2 > no3) && (no2 > no1)) 
        printf("\n %d is greatest",no2);

    //other conditions are false than number 3 is greater 
    else 
        printf("\n %d is greatest",no3); 
    return 0; 
}

Output

Insert value of first number: 1
Insert value of second number: 2
Insert value of third number: 3
3 is greatest