Q. Write a function to calculate largest of 3 numbers.
Answer:
#include<iostream>
using namespace std;
double largest_of_three(double,double,double);
int main()
{
double a,b,c;
cout<<"a = "; cin>>a;
cout<<"b = "; cin>>b;
cout<<"c = "; cin>>c;
cout<<"Largest: "<<largest_of_three(a,b,c)<<endl;
}
double largest_of_three(double a, double b, double c)
{
if (a > b && a > c)
return a;
else if (b>c && b>a)
return b;
else return c;
}
Answer:
#include<iostream>
using namespace std;
double largest_of_three(double,double,double);
int main()
{
double a,b,c;
cout<<"a = "; cin>>a;
cout<<"b = "; cin>>b;
cout<<"c = "; cin>>c;
cout<<"Largest: "<<largest_of_three(a,b,c)<<endl;
}
double largest_of_three(double a, double b, double c)
{
if (a > b && a > c)
return a;
else if (b>c && b>a)
return b;
else return c;
}
No comments:
Post a Comment