Here are the function prototypes for your homework
Write out the actual functions themselves
Also, create a main function that demonstrates that all four functions work
The user should be able to provide four values to your program (three floats and an int)
Your program should then use your four new functions and also display the results to the user
NONE of these functions should print values themselves
float sum( float x, float y, float z ); // returns the sum of three floats
float mean( float x, float y, float z ); // returns the mean (average) of three floats
float median( float x, float y, float z ); // returns the middle value of three floats
unsigned long long factorial( unsigned int x ); // returns the factorial of the integer x
program in c++
#include
using namespace std;
float sum( float x, float y, float z ); // returns the sum of three
floats
float mean( float x, float y, float z ); // returns the mean
(average) of three floats
float median( float x, float y, float z ); // returns the middle
value of three floats
unsigned long long factorial( unsigned int x ); // returns the
factorial of the integer x
int main()
{
float a,b,c;
unsigned int d;
cout<<"Enter any three float numbers: ";
cin>>a>>b>>c;
cout<<"Enter any integer number";
cin>>d;
cout<<"\nSummation = "<
}
float sum( float x, float y, float z)
{
float p;
p=x+y+z;
return(p);
}
float mean( float x, float y, float z)
{
float p;
p=(x+y+z)/3;
return(p);
}
float median( float x, float y, float z)
{
float second_max;
if ( x < y )
{
if ( y < z ) second_max = y;
else second_max = ( x < z ? z : x );
}
else
{
if ( x < z ) second_max = x;
else second_max = ( y < z ? z : y );
}
// printf( "second maximum value is %d\n ", second_max );
return (second_max);
}
unsigned long long factorial( unsigned int x )
{
int c;
long result = 1;
for( c = 1 ; c <= x ; c++ )
result = result*c;
return ( result );
}
Get Answers For Free
Most questions answered within 1 hours.