Write a C C++ program to find greater in two numbers

Write a C C++ program to find greater in two numbers

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

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

Flowchart to find greater in two numbers

Greater in two numbers flowchart

C program to find greater in two numbers

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

C++ program to find greater in two numbers

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

Output of C C++ program to find greater in two numbers

Enter two numbers : 30 90
Greater number = 90
Enter two numbers : 45 22
Greater number = 45
Enter two numbers : 50 50
Greater number = 50

List of related selection logic programs

  1. Absolute value of number (simple if)
  2. Checking odd or even number (if else)
  3. Checking leap year (if else)
  4. Finding grade from percent (else if ladder)
  5. Total percent and division (else if ladder)
  6. Greatest in three numbers (nested if)
  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