using a C++ code find the largest number from two numbers. also considering the case that the two numbers are equal.
Code:
#include <iostream>
//function to find the largest of any given two numbers
int largest(int o,int t){
if (o==t) return o;
else if(o>t) return o;
else return t;
}
//main function testing the above
int main() {
std::cout << "largest(5,3)="<<largest(5,3)<<std::endl;
std::cout << "largest(1,3)="<<largest(1,3)<<std::endl;
std::cout << "largest(2,2)="<<largest(2,2)<<std::endl;
}
output:
largest(5,3)=5
largest(1,3)=3
largest(2,2)=2
Get Answers For Free
Most questions answered within 1 hours.