The objective of the programming assignment was to use iteration to calculate the values of sin and cos with the Taylor’s series formula. The program inputs were the value of x (in radians) that would be used to calculate sin and cos and the value of N which was the number of terms that would be included in the Taylor’s series expansion. The program outputs were three different tables. The first table consisted of the value of N, N factorial and the x-value raised to the value N. The second table consisted of the value of N, the x-value raised to the value of N divided by N factorial and the value of sin. The third table consisted of the same values as the sin table, but it prints out the values for cos instead. One error handling that was required was to do an error correction to the value of N so that the user could only type in a value of N that was greater than or equal to one.
Design:
The data structure that was mainly used in the program was a double variable. The pro of using this variable …show more content…
I extended the code with three for loops to calculate three different tables. The first task was to read the values of x and N into a variable. After the task was completed, the next step was to print out the values of the first table. I began to implement a power function without using the pow function in the (-- removed HTML --) library. I also used the same for loop to calculate N factorials that depended on the user’s input of the value of N. The last value that was printed in the first table was the x-value raised to the N which were both inputs that the user control. The values of the first table were calculated by using the values in the previous row to calculate the next row. For example, if the user enters an x-value of 0.1 and an N value of 3, the for loop would multiply 0.1 three times to receive