Write a C C++ program to find greatest in three numbers

Write a C C++ program to find greatest in three numbers

C के विभिन्न control statements को जानने के लिए देखें— Control statements in C

If statement और decision making statements के बारे में अधिक जानने के लिए देखें— If statements in C

Flowchart to find greatest in three numbers

Finding greatest in three numbers flowchart

C program to find greatest in three numbers

#include<stdio.h>
int main()
{
    int n1,n2,n3;
    printf("Enter three numbers: ");
    scanf("%d%d%d",&n1,&n2,&n3);
    if(n1>n2)
    {
        if(n1>n3)
            printf("Greatest number = %d",n1);
        else
            printf("Greatest number = %d",n3);
    }
    else
    {
        if(n2>n3)
            printf("Greatest number = %d",n2);
        else
            printf("Greatest number = %d",n3);
    }
    return 0;
}

C++ program to find greatest in three numbers

#include<iostream>
using namespace std;
int main()
{
    int n1,n2,n3;
    cout<<"Enter three numbers: ";
    cin>>n1>>n2>>n3;
    if(n1>n2)
    {
        if(n1>n3)
            cout<<"Greatest number = "<<n1;
        else
            cout<<"Greatest number = "<<n3;
    }
    else
    {
        if(n2>n3)
            cout<<"Greatest number = "<<n2;
        else
            cout<<"Greatest number = "<<n3;
    }
    return 0;
}

Output of C C++ program to find greatest in three numbers

Enter three numbers: 4 8 5
Greatest number = 8
Enter three numbers: 33 12 15
Greatest number = 33
Enter three numbers: 40 40 40
Greatest number = 40

List of programs based on if statement and other control statements

  1. Absolute value of number (simple if)
  2. Checking odd or even number (if else)
  3. Checking leap year (if else)
  4. Greater in two numbers (if else)
  5. Finding grade from percent (else if ladder)
  6. Total percent and division (else if ladder)
  7. Simple calculator program (switch case single case)
  8. Switch between Mon to Sun (switch case single case)
  9. Checking vowel or consonant (switch case multiple case)
  10. Number of days in a month (switch case multiple case)
  11. Unconditional Branching (break continue and goto)
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer