In C Language (not C++) Write ALL of the following steps in ONE program. Write a
ID: 3676589 • Letter: I
Question
In C Language (not C++) Write ALL of the following steps in ONE program.
Write and test the following function that returns the maximum value of the two parameters that are passed to it. The prototype for this function is:
double maximum(double valA, double valB);
Write and test the following function that returns the average of the four parameters that are passed to it. The prototype for this function is:
double mean(double valA, double valB, double valC, double valD);
Write and test the following function that returns “true” if the integer is even and false otherwise. (Consider 0 an even number). The prototype for this function is:
bool isEven(int value);
Write and test a function that draws a line of characters. The function will receive a number between 1 and 20, inclusive, and a character; then it should draw a line of these characters. The function should draw a line using the character and the number as the length of the line. Here is the prototype for this function:
void drawLine(int valA, char valB);
For example, if this function is given the number 3 and the character B as arguments, it should print out BBB. It should use a loop to print out the character, length times.
Write and test a function that receives three values. The function returns true if the third value, valueC, is the product of the first two parameter values: valueA and valueB. The prototype for this function is:
bool isProduct(int valueA, int valueB, int valueC);
Write and test a function that the calculates area of a circle. The function receives one value, radius of type double, and returns the value;
double calcArea(double radius);
Write and test a function that the calculates area of a rectangle. The function receives two values, length and width and returns the value;
double calcArea(double length, double width);
Explanation / Answer
#include <stdio.h>
#include <stdbool.h>
double maximum(double valA, double valB)
{
if(valA > valB) return valA;
else return valB;
}
double mean(double valA, double valB, double valC, double valD)
{
double t = valA + valB + valC + valD;
return t/4;
}
bool isEven(int value)
{
if( value%2 == 0) return true;
else return false;
}
void drawLine(int valA, char valB)
{
int i;
for (i = 0; i < valA; ++i)
{
printf("%c",valB);
}
}
bool isProduct(int valueA, int valueB, int valueC)
{
int t = valueA * valueB;
if ( valueC == t )
{
return true;
}
else return false;
}
double calcarea(double length, double width)
{
double area = length * width;
return area;
}
double calcArea(double radius)
{
double area = 3.14*radius*radius;
return area;
}
int main()
{
printf("Max of 10 and 4 is %lf ",maximum(10,4) );
printf("Mean of 1, 2, 3, 4 is %lf ",mean(1,2,3,4) );
if(isEven(10)== true) printf("10 is Even ");
else printf("10 is not Even ");
if (isEven(11) == true) printf("11 is Even ");
else printf("11 is not Even ");
printf("Drawing line with number10 and character C ");
drawLine(10,'C');
printf(" ");
if(isProduct(5,2,10)== true) printf("10 is product of 5 and 2 ");
else printf("10 is not product of 5 and 2 ");
if(isProduct(20,2,9)== true) printf("20 is product of 2 and 9 ");
else printf("20 is not product of 2 and 9 ");
printf("Area of rectangle with length = 10 and width = 10 is %lf units ", calcarea(10,10));
printf("Area of circle with radius 10 is %lf uints ",calcArea(10) );
return 0;
}