How to Find Greatest of Two Numbers in C:-
In the C programming language, the greatest of numbers can be identified with the help of the IF-ELSE statement. The user is asked to insert two integers. The numbers inserted are then calculated using a set of programs 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.
ALGORITHMS:-
Step 1:- Start
Step 2:- Insert two integers no1 and no2 from the user with the help of scanf statement.
Step 3:- Check if the no1 is bigger in value than no2 using the if statement.
Step4: - If no1 is greater, then print no1 using the print statement, if the case is vice versa then check whether no2 is greater than no1 with the help of the else if statement.
Step 5:If no2 is greater than no1, then print no2 using print statement.
CODE: -#include<stdio.h>
int main()
{
int num1,num2;
printf("enter two numbers:");
scanf("%d\n %d",&num1,&num2);
if(num1 > num2)
printf("%d is greatest",num1);
else if(num2 > num1)
printf("%d is greatest",num2);
else
printf("%d and %d are equal",num1,num2);
return 0;
int num1,num2;
printf("enter two numbers:");
scanf("%d\n %d",&num1,&num2);
if(num1 > num2)
printf("%d is greatest",num1);
else if(num2 > num1)
printf("%d is greatest",num2);
else
printf("%d and %d are equal",num1,num2);
return 0;
}
Comments
Post a Comment