write a program to find largest among two numbers using if else
Answers
Answered by
0
Program (In C++) :
// C++ program to find the greatest of two numbers
#include<iostream>
using namespace std;
int main()
{
int num1, num2;
cin >> num1 >> num2;
if(num1 > num2)
{
count << num1 << ” is greater” << endl;
}
else
{
count << num2 << ” is greater” << endl;
}
return 0;
}
HOPE THIS HELPS ✌️✌️
Please mark as the brainliest if that helped
Answered by
0
Points to be remembered:-
- We have to see first if the condition checks whether a is greater than b. This condition must be True For a is greater than b.
- But the condition checks whether b is greater than a.This condition must be true for b is greater than a.
- If we find both of the above two conditions as fail then it indicates that they are equal.
Code:-
C ode:-
#include <stdio.h>
int main() {
int a, b;
printf("Please Enter Two different values\n");
scanf("%d %d", &a, &b);
if(a > b)
{
printf("%d is Largest\n", a);
}
else if (b > a)
{
printf("%d is Largest\n", b);
}
else
{
printf("Both are Equal\n");
}
return 0;
}
Sample output:-
Lets enter
- a=35
- b=27
Similar questions