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

//**Using C and Start only with #include <stdio.h> no other functions. **// Writ

ID: 3634318 • Letter: #

Question

//**Using C and Start only with #include <stdio.h> no other functions. **//

Write a program that prompts the user for the double-precision1 legs of a right triangle
and prints the hypotenuse and the smallest angle (in degree) of that triangle with 1-decimal point
precision.
Include a function void Compute(double *cp, double *anglep, double a, double b) that computes the hypotenuse and the smallest angle of the right triangle with legs a; b, and stores them respectively in the variables pointed by cp and anglep.

Ex)

1) Legs: (output) 3.0 4.0(inpt)

Hypotenuse: 5.0 (output)

Smallest angle: 36.9 degree (output)

2) Legs: (output) 5 10 (input)

Hypotenuse: 11.2 (output)

Smallest angle: 26.6 degree (output)

3) Legs: (output) 2.5 2.5(input)

Hypotenuse: 3.5 (output)

Smallest angle: 45.0 degree (output)

Explanation / Answer

Dear,

Program :

/*This program computes the Hypotenuse and smallest angle

in a right triangle*/

/*header files*/

/*needed for I/O operations*/

#include <stdio.h>

/*needed for math functions*/

#include <math.h>

/*constant declaration*/

#define pi 3.14159265

/*function to compute angle and hypotenuse*/

void Compute(double *cp, double *anglep, double a, double b)

{

     double alpha, beta;

     /*calculating hypotenuse */

     *cp=sqrt((a*a)+(b*b));

     /*calculating angles */

     alpha = (180/pi)*atan(b/a);

     beta = (180/pi)*atan(a/b);

     /*condition to find the smallest angle */

     if (alpha > beta)

          *anglep = beta;

     else if(alpha < beta)

          *anglep = alpha;

     else

          *anglep = alpha;

}

/*main function*/

void main()

{

     /*variables*/

     double a=5, b=10, cp, anglep;

     /*reading the values from user*/

     printf("Legs: ");

     scanf("%lf%lf", &a, &b);

     /*calling the function Compute to compute angle and hypotenuse*/

     Compute(&cp, &anglep, a, b);

     /*Display results*/

     printf("Hypotenuse: %.1lf", cp);

     printf(" Smallest angle: %.1lf degree.", anglep);

}

Output:

(~)$ a.out

Legs: 5 10

Hypotenuse: 11.2

Smallest angle: 26.6 degree.

(~)$ a.out

Legs: 3.0 4.0

Hypotenuse: 5.0

Smallest angle: 36.9 degree.

(~)$ a.out

Legs: 2.5 2.5

Hypotenuse: 3.5

Smallest angle: 45.0 degree.


Hope this would help you.