Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

21.Write the definition of a function that takes as input three numbers and retu

ID: 3836728 • Letter: 2

Question

21.Write the definition of a function that takes as input three numbers and returns the sum of the first two numbers multiplied by the third number. (Assume that the three numbers are of type double.)

23.A program contains the following function.
int cube(int num)
{
return num * num * num;
}
Write a statement that passes the value 4 to this function and assigns its return value
to the variable result.

24.What is the error in following function definitions?
a) void total(int value1, value2, value3)
{
return value1 + value2 + value3;
}
b) double average(int value1, int value2, int value3)
{
double average;
average = value1 + value2 + value3 / 3;
}

Explanation / Answer

21.

// Result is the function with x,y,z as parameters of double type

Result (double x, double y, double z)

{

double result;

result= (x+y)*z; // calculation for desired output according to the given question above

return result; // returns the value

}

Output:

If x=1 y=2 z=3

Result= 9

23.

Given code

int cube(int number)

{

return number*num*num;

}

#include <studio.h>

main()

{

int m=cube(4); // calling of the function cube and the assignment of returned value to m variable

Printf("cube of 4 is %d",m);

}

Output: cube of 4 is 64

24

a) the function definition should be as

Function _type function _name(variable_type variable, variable _type variable 2)

{

//Function code

return return_variable;

}

Here in given question the first variable is declared as int and other two are not declared

This is the wrong in function

b) in this question the function didnot specify that what to return back

The average value is not returned

return average;

Statement want to be there in function definition

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote