For C++ Define a function called hypotenuse that calculates the length of the hy
ID: 3793278 • Letter: F
Question
For C++ Define a function called hypotenuse that calculates the length of the hypotenuse of a right triangle when the other two sides are given. The function should take two arguments of type double and return the hypotenuse as a double Test your program with the side values specified as follows: Write a function integerPowe(base. exponent) that returns the value of base^exponent For example, mtegerPower(3, 4) * 3 * 3 *3 * 3. Assume that exponent is an positive, nonzero integer, and base is an integer Function integerPower should use for to control the calculation Do not use any math library functions. Write the int main(void) function as a driver program and call the above two functions result with sample Input/Output
Explanation / Answer
#include <stdio.h>
#include <math.h>
double hypotenuse(double side1,double side2)
{
return sqrt(side1 * side1 + side2 * side2);
}
int integerPower(int base, int exponent)
{
int i=0,res=1;
for(;i<exponent;i++)
{
res *= res;
}
return res;
}
int main()
{
double side1,side2;
int base,exponent;
printf("Enter Triangle Side 1: ");
scanf("%f", &side1);
printf("Enter Triangle Side 2: ");
scanf("%f", &side2);
printf("Hypotenuse: %f ",hypotenuse(side1,side2));
printf("Enter the base: ");
scanf("%d",base);
printf("Enter the exponent(Non-zero and positive): ");
scanf("%d",exponent);
printf("base^exponent = %d ",integerPower(base, exponent));
return 0;
}
Output:
Enter Triangle Side 1:
10
Enter Triangle Side 2:
20
Hypotenuse: 200.000000000
Enter the base:
2
Enter the exponent:
3
base^exponent = 8
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.