Question: Pseudocode for the following C program #include // this function takes angle as radian and returns sine of x float sine(float x) { float t

Pseudocode for the following C program

#include

// this function takes angle as radian and returns sine of x float sine(float x) { float t = x; float sinex = x; int k; for(k=1; k<=100; k++) { t = (t*(-1) * x*x) / (2*k * (2*k+1)); sinex = sinex + t; } return sinex; }

// this function takes angle as radian and returns cosine of x float cosine(float x) { float t = 1, cosinex = 1; int k; for(k=1; k<=100; k++) { t = (t*(-1)* x*x) / (2*k * (2*k-1)); cosinex = cosinex + t; } return cosinex; }

int main() { int choice; float x; // asking user to enter choice printf("Choose function [1] sine(x) or [2] cosine(x) or [3] tangent(x): "); scanf("%d", &choice); // if user chose 1 then printing sine of x if (choice == 1) { printf("Enter angle x in radians: "); scanf("%f", &x);

float sin_x = sine(x); // calling sine printf("sine(%.2f) = %.6f", x, sin_x); }

// if user chose 2 then printing cosine of x if (choice == 2) { printf("Enter angle x in radians: "); scanf("%f", &x); float cos_x = cosine(x); // calling cosine printf("cosine(%.2f) = %.6f", x, cos_x);

} // if user chose 3 then printing tangent of x if (choice == 3) { printf("Enter angle x in radians: "); scanf("%f", &x); // calling sine and cosine for calculating tangent(x) by dividing sine(x) and cosine(x) float tan_x = sine(x) / cosine(x); printf("tangent(%.2f) = %.6f", x, tan_x); }

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!