Pointer Sin Cos Angle

PHOTO EMBED

Sun Jun 09 2024 11:28:59 GMT+0000 (Coordinated Universal Time)

Saved by @meanaspotato #c #pointer

#include <stdio.h>
#include <math.h>

void compute_trig(float deg, float* sin_angle, float* cos_angle);

int main(void)
{
    float sin_result = 0.0f;
    float cos_result = 0.0f;
    float angle = 0.0f;
 
    printf("Angle? \n");
    scanf("%f", &angle);
    // TODO: Call compute_trig
    compute_trig(angle,&sin_result,&cos_result);
    
    printf("sin(%f) is %f\n", angle, sin_result);
    printf("cos(%f) is %f\n", angle, cos_result);
 
    return 0;
}

void compute_trig(float deg, float* sin_angle, float* cos_angle)
{
    float pi = 3.14159f;
    float radians = deg * pi / 180.0f;
    // TODO: Compute sine angle...
    *sin_angle = sinf(radians);
    
    // TODO: Compute cosine angle...
    *cos_angle = cosf(radians);
}
content_copyCOPY

The purpose of this exercise is to provide students with experience in C programming related to function prototypes, pointers, and trigonometric calculations. Students are expected to implement a function called compute_trig that calculates the sine and cosine of a given angle in degrees and returns the results through pointers. The function must have no side-effects. Requirements Function Prototype Declare a function prototype for compute_trig with the following characteristics: Return Type: void Parameters: A float for the angle in degrees (float deg) A pointer to a float for the sine result (float* sin_angle) A pointer to a float for the cosine result (float* cos_angle) Function Definition Define the compute_trig function to perform the following operations: Convert the angle from degrees to radians. Calculate the sine of the angle and store the result in the variable pointed to by sin_angle. Calculate the cosine of the angle and store the result in the variable pointed to by cos_angle. For example: Input Result 87 7 Angle? sin(87.000000) is 0.998629 cos(87.000000) is 0.052337