C++ Program Largest of two Numbers without If-Else

Ram Pothuraju

This is a simple  Program in C++ for the Largest of 2 without If else statement. It is also usually asked in Interviews.



Largest number without If-Else
#include <iostream.h>
int main()
{
float a=3,b=2;

float c=((a+b)/2) + ((a-b)/2);           //c=2.5+0.5=3.0

cout<<"The largest number of the two is "<<c;
return 0;
}

Here we use a simple logic to find the largest of two without using the If Else Statement.

Post a Comment

0Comments

Post a Comment (0)