Computer Science, asked by keerthijoy902, 2 months ago

write a program to find largest among two numbers using if else​

Answers

Answered by krrew
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 NewGeneEinstein
0

Points to be remembered:-

  1. 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.
  2. But the condition checks whether b is greater than a.This condition must be true for b is greater than a.
  3. 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

\boxed{\begin{array}{c}\sf Please\:enter\:two\:different\:values \\ \sf 35 \\ \sf 27 \\ \sf 35\:is\:largest\end{array}}

Similar questions