Define a function called hypotenuse that calculates the length of the hypotenuse
ID: 3790589 • Letter: D
Question
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 integer Power(base, exponent) that returns the value of base For example, integer Power(3, 4) = 3 * 3 * 3 * 3. Assume that exponent is a positive, nonzero integer, and base is an integer. Function integer Power 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>
double hypoteuse1(double s1,double s2) {
//formula for length of hypoteuse triangle is c^2=a^2+b^2
double len,square;
printf("S1 %lf s2 %lf",s1,s2);
square=(s1*s1)+(s2*s2); //or square=integerpower(s1,2)+integerpower(s2,2);
len=sqrt(square);
printf("Length of triangle is %f ",len);
return len ;
}
int integerpower(int base,int expt){
int i,temp,ip;
temp=1;
printf("Base Exponent %d %d ",base,expt);
if(base>0 && expt>0 )
{
for(i=1;i<=expt;i++)
{
temp=temp*base;
}
ip=temp;
printf("%d",ip);
}
else
{
printf("Enter Non zero and positive values ");
break;
}
return ip;
}
int main(void) {
int b,e,power;
double side1,side2,lentriangle;
printf(" Enter side1 value ");
scanf("%lf", &side1);
printf(" Enter side2 value");
scanf("%lf", &side2);
printf("side 1 %lf side2 %lf",side1,side2);
printf("Enter the Base and Exponent value:");
scanf(" %d %d",&b,&e);
printf("b %d e %d",b,e);
lentriangle=hypoteuse1(side1,side2);
printf(" length of triangle of side1: %lf and side2 %lf is %lf ",side1,side2,lentriangle);
power=integerpower(b,e);
printf("integerpowerof base %d and Exponent %d is %d ",b,e,power);
return ;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.