Question

I need a simple program in C language that calculates the values of Sine, Cosine, and Tangent of values given in degrees. It has to be a range of values between 0 and 360(integer values). The output should be a table of values showing Sin, Cos and Tan values. The complete computation and printing of the table must be done inside a function. The function also returns to the main program with 3 output arguments: It also needs to show the number of negative values for Sin, the number of negative values for Cos, and the number of indeterminate(undefined) values for Tangent (typically these are infinity values. For the purposes of this program they will be anything outside the -100 to 100 range).

The main program should prompt the user to enter 2 integers in the range of values to be computed. Making sure that the user does not enter a range outside of 0 and 360. If they do, the program should display an error message and ask them to re-enter 2 numbers. After the user enters a pair of valid integers, the program stops, there is no need to loop to ask for more inputs as long as both inputs are valid. Also, the program should not allow the user to enter inputs with a range of more than 90 degrees (ex. 0 and 90; 90 to 180, 170 to 240, etc.).

After the function is called to print the table of values, the printing 3 additional items (# of negative values for Sine, Cosine and undefined values for Tangent) must be done in the main program (not in the function where they are computed).


The function needs to have 2 integers as input arguments (for range). The function does not return any value (void function) but has 3 output arguments (pointers to integers) one for the total count for each of the items mentioned above. The function has to use a FOR loop to compute the range of Sine, Cosine, Tangent values from the smallest to the largest in increments of 5 (It can use the Math library functions sin, cos and tan). The printing of all the table of computed values must be done inside the FOR loop (in the function). The function can have any other print statements as needed to be able to print a clean, well-aligned table of values with a heading for each column.

Output should look something like this...

This program finds the Sine, Cosine and Tangent values for angles between 0 and 360 degrees Please enter the start and ending values (between 0 and 360 degrees) for computation Sine, Cosine and Tangent for degrees 0 to 90 in steps of 5 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 Sine: 0.0000 0.0872 0.1736 0.2588 0.3420 0.4226 0.5000 0.5736 0.6428 0.7071 0.7660 0.8192 0.8660 0.9063 0.9397 0.9659 0.9848 0.9962 1.0000 Cosine: 1.0000 0.9962 0.9848 0.9659 0.9397 0.9063 0.8660 0.8192 0.7660 0.7071 0.6428 0.5736 0.5000 0.4226 0.3420 0.2588 0.1736 0.0872 0.0000 Tangent: 0.0000 0.0875 0.1763 0.2679 0.3640 0.4663 0.5773 0.7002 0.8391 1.0000 1.1918 1.4281 1.7320 2.1445 2.7475 3.7320 5.6712 11.4299 XXX o nooo na a 96 08 10 Number of Negative Sine values: 0 Number of Negative Cosine values: 0 Number of Indeterminate Tangent values: 1

0 0
Add a comment Improve this question Transcribed image text
Answer #1


Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you

#include <stdio.h>
#include <math.h>
void printTable(int start, int end, int *sineCount, int *cosCount, int *tanCount);
int main(){
int start, end;
int sineCount, cosCount, tanCount;
printf("\n\tPlease enter start and end angles in the range of 0-360 degrees.");
printf("\n\tThe angles should be separated more than 90 degrees\n");
printf("Enter the starting angle: ");
scanf("%d", &start);
printf("Enter the ending angel: ");
scanf("%d", &end);
while(start < 0 || end < 0 || start > end || end - start > 90 || start > 360 || end > 360){
printf("Invalid start or end angle. Please enter valid values!\n");
printf("Enter the starting angle: ");
scanf("%d", &start);
printf("Enter the ending angel: ");
scanf("%d", &end);
}
printTable(start, end, &sineCount, &cosCount, &tanCount);
printf("No. of negative sine values: %d\n", sineCount);
printf("No. of negative cosine values: %d\n", cosCount);
printf("No. of indeterminate tangent values: %d\n", tanCount);
}
void printTable(int start, int end, int *sineCount, int *cosCount, int *tanCount){
int angle;
double radians, s, c, t;
*sineCount = 0;
*cosCount = 0;
*tanCount = 0;
printf("%10s %10s %10s %10s\n", "Angle", "Sine", "Cosine", "Tangent");
for(angle = start; angle <= end; angle += 5){
radians = angle * M_PI / 180;
s = sin(radians);
c = cos(radians);
t = tan(radians);
if(s < 0)
(*sineCount)++;
if(c < 0)
(*cosCount)++;
if(t < -100 || t > 100)
{
(*tanCount)++;
printf("%10d %10.4lf %10.4lf %10s\n", angle, s, c, "XXX");
}
else
printf("%10d %10.4lf %10.4lf %10.4lf\n", angle, s, c, t);
}
printf("\n");
}

Add a comment
Know the answer?
Add Answer to:
I need a simple program in C language that calculates the values of Sine, Cosine, and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • NEED THE MATLAB CODE Sometimes it is convenient to have a table of sine, cosine, and...

    NEED THE MATLAB CODE Sometimes it is convenient to have a table of sine, cosine, and tangent values instead of using a calculator. Create a table of all three of these trigonometric functions for angles from 0 to 4pi. Prompt the user for the increment in radians. Use disp and fprintf to create a table with a title, column headings, and appropriate spacing. Your table should contain a column for the angle, followed by the three trigonometric function values.  

  • **This is for the C Language. Trigonometric Calculator Specification You are required to write a program...

    **This is for the C Language. Trigonometric Calculator Specification You are required to write a program that calculates and displays values of the trigonometric functions sine, cosine, and tangent for user-supplied angular values. The basic program must comply with the following specification. 1. When the program is run, it is to display a short welcome message. TRIG: the trigonometric calculator 2. The program shall display a message prompting the user to enter input from the keyboard. Please input request (h-help,...

  • PYTHON:please display code in python Part 1: Determining the Values for a Sine Function Write a...

    PYTHON:please display code in python Part 1: Determining the Values for a Sine Function Write a Python program that displays and describes the equation for plotting the sine function, then prompts the user for the values A, B, C and D to be used in the calculation. Your program should then compute and display the values for Amplitude, Range, Frequency, Phase and Offset. Example input/output for part 1: Part 2: Displaying a Vertical Plot Header A vertical plot of the...

  • Python 3.7 to be used. Just a simple design a program that depends on its own. You should also not need to import anythi...

    Python 3.7 to be used. Just a simple design a program that depends on its own. You should also not need to import anything. No code outside of a function! Median List Traversal and Exception Handling Create a menu-driven program that will accept a collection of non-negative integers from the keyboard, calculate the mean and median values and display those values on the screen. Your menu should have 6 options 50% below 50% above Add a number to the list/array...

  • I need help with my homework please. I should write this program in C++ language and...

    I need help with my homework please. I should write this program in C++ language and use Inventory.h file (header file), Inventory.cpp file (implementation file), and main.cpp file (main program). This is the program: Demonstrate the class in a driver program. Input validation, don’t accept negative values for item number, quantity, or cost. 6. Inventory Class Design an Inventory class that can hold information and calculate data for items ma retail store's inventory. The class should have the following private...

  • this is a C++ program! You will write a program that performs the following tasks for...

    this is a C++ program! You will write a program that performs the following tasks for a simple mathematical calculator: (1) Open a user-specified file for input. Prompt for the name of the file, read it into a string variable, echo print it to the terminal and then open it. If the file is not opened, enter into a loop that prints out an error message, resets the input file stream variable (see the hints section), obtains a new file...

  • This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named...

    This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named Budgeter.java. To use a Scanner for console input, you must import java.util.*; in your code. This program prompts a person for income and expense amounts, then calculates their net monthly income. Below are two example logs of execution from the program. This program’s behavior is dependent on the user input (user input is bold and underlined below to make it stand out and differentiate...

  • Description Write C++ code that correctly input and output information. (Moving data to and from the...

    Description Write C++ code that correctly input and output information. (Moving data to and from the screen and to and from text files. Also inputting predefined functions, etc., from included libraries.) Problem Description Consider a data file that has geometrical angle values in degrees. Angle values may be on one line, several lines, or any other white space separated format. Fig. 1 below shows one possible format, but other formats are possible. 12.9 100.8 270.5 300.6 120.8 There are no...

  • C++ i have started the program i just need help finishing it. This chapter is on...

    C++ i have started the program i just need help finishing it. This chapter is on functions. If you write this assignment without creating functions (main itself does not count) then the maximum score you can receive is 10% of the grade even if the output is perfectly correct. Write a modular program with the following Functions: Main, PrintHeading, PrintTuitionTable The Main Function should ask the user for a Tuition like assignment 6. Then it should call the PrintHeading function,...

  • C programm , ´hello i need your help -Given the C program primes.c with the following main method: int main() { int num, res; char buffer[11]; bool finished = false; while (!finished)...

    C programm , ´hello i need your help -Given the C program primes.c with the following main method: int main() { int num, res; char buffer[11]; bool finished = false; while (!finished) { printf("Enter n > 0 or quit\n"); scanf("%10s", buffer); if (strcmp(buffer, "quit") == 0) { finished = true; } else { // Convert input to number and compute n-th prime num = atoi(buffer); if (num > 0) { res = nth_prime(num); printf("Prime #%d is %d\n", num, res); }...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT