Given two integer values, return whichever value is larger. However if the two values have the same remainder when divided by 5, then the return the smaller value. However, in all cases, if the two values are the same, return 0.
#include <iostream>
using namespace std;
int func(int,int);
int main()
{
int a,b;
cout<<"Enter First Number: ";
cin>>a;
cout<<"\nEnter Second Number: ";
cin>>b;
func(a,b);
return 0;
}
int func(int x,int y)
{
int rem1,rem2;
rem1=x%5;
rem2=y%5;
if(x==y)
return 0;
else
{
cout<<"\nAnswer is: ";
if(rem1==rem2)
x>y? cout<<y:cout<<x; //Conditional Operator
else
x>y? cout<<x:cout<<y;
}
}
#include <iostream>
using namespace std;
int func(int,int);
int main()
{
int a,b;
cout<<"Enter First Number: ";
cin>>a;
cout<<"\nEnter Second Number: ";
cin>>b;
func(a,b);
return 0;
}
int func(int x,int y)
{
int rem1,rem2;
rem1=x%5;
rem2=y%5;
if(x==y)
return 0;
else
{
cout<<"\nAnswer is: ";
if(rem1==rem2)
x>y? cout<<y:cout<<x; //Conditional Operator
else
x>y? cout<<x:cout<<y;
}
}