Use simple if to Find Greater of Two Numbers

By | June 18, 2019

This is a “Find Greater of Two Numbers” C program to find greater number of the two given numbers. It uses a set of simple if statements to find either first number is greater or second number. It also tells if both numbers are equal.

/*
Write a C Program 
to input two numbers and check
which is greater or both are equal
using simple if statement 
*/
#include<stdio.h>

int main()
{
   int num1, num2;
   printf("Enter First Number=");
   scanf("%d", &num1);
   printf("Enter 2nd Number=");
   scanf("%d", &num2);
   if(num1 > num2)
     printf("First Number %d is greater than Second Number %d ", num1,num2);
   if(num2 > num1)
     printf("Second Number %d is greater than First Number %d ", num2,num1);
   if(num1 == num2)
     printf("First Number %d is equal to Second Number %d ", num1,num2);
   
   return 0;
}

Here is an image that shows a sample output from a sample run of the program.

C Program to find out the greater number of two given numbers

C Program to find out the greater number of two given numbers

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *