





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

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
- Positive or Negative number: C | C++ | Java
- Even or Odd number: C | C++ | Java
- Sum of First N Natural numbers: C | C++ | Java
- Sum of N natural numbers: C | C++ | Java
- Sum of numbers in a given range: C | C++ | Java
- Greatest of two numbers: C | C++ | Java
- Greatest of the Three numbers: C | C++ | Java
- Leap year or not: C | C++ | Java
- Prime number: C | C++ | Java
- Prime number within a given range: C | C++ | Java
- Factorial of a number: C | C++ | Java
- Sum of digits of a number: C | C++ | Java
- Reverse of a number : C | C++ | Java
- Palindrome number: C | C++ | Java
- Armstrong number : C | C++ | Java
- Armstrong number in a given range : C | C++ | Java
- Fibonacci Series upto nth term : C | C++ | Java
- Factorial of a number : C | C++ | Java
- Power of a number : C | C++ | Java
- Factor of a number : C | C++ | Java
- Strong number : C | C++ | Java
- Perfect number : C | C++ | Java
- Automorphic number : C | C++ | Java
- Harshad number : C | C++ | Java
- Abundant number : C| C++ | Java
- Friendly pair : C | C++ | Java

Login/Signup to comment