For this programming assignment4 you need to submit only ONE

For this programming assignment#4, you need to submit only ONE source code file. 1. 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 Side 1 Side 2 Triangle 3.0 4.0 12.0 5.0 8.0 15.0 2. Write a function integerPower(base, exponent) that returns the value of base exponent For example, integerPower(3, 4) 3* 3 3 3. Assume that exponent isa positive, nonzero integer, and base is an integer. Function integerPower should use for to control the calculation. Do not use any math library functions. 3. Write the int main(void) function as a driver program and call the above two functions result with sample Input/Output.

Solution

#include<stdio.h>
#include<math.h>
// method to calculate hypotenuse
double hypotenuse(double side1, double side2)
{
   double hyp = sqrt(side1*side1 + side2*side2); //calculate hypotenuse value
   return hyp;
}
//method to calculate integer power
long integerPower(int base, int exponent)
{
   long pow = 1; //initialize to 1
   int i;
   for (i=0;i<exponent;i++)
      pow *= base; // calculate power by repeated multiplication of base
   return pow;
}
int main(void)
{
   double side1, side2;
   int base, exp;

   printf(\"Enter side 1: \");
   scanf(\"%lf\",&side1); // accept user input for side 1
   printf(\"Enter side 2: \");
   scanf(\"%lf\",&side2); // accept user input for side 2
   printf(\"Hypotenuse: %lf\ \", hypotenuse(side1,side2)); //display hypotenuse value

   printf(\"Enter base: \");
   scanf(\"%d\", &base); // accept user input for base
   printf(\"Enter exponent: \");
   scanf(\"%d\", &exp); //accept user input for exponent
   printf(\"Power: %ld\ \", integerPower(base,exp)); // display power value

   return 1;
}

 For this programming assignment#4, you need to submit only ONE source code file. 1. Define a function called hypotenuse that calculates the length of the hypot

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site