I have a homework assignment where I'm supposed to calculate the values for theta when given the value of pi and I'm sure I have to use the "for" loop however I don't know how the code for this would work.
Here is what I have so far:
Here's the problem if it helps:Code:double theta (int limit); const double pi = 3.141592653589793; int main (void) { //Local Declaration int limit; //Statements printf("pi = %lf\n", pi); limit=5; printf ("\nNumber of terms = %d\nTheta = %lf\nDifference between theta and pi = %lf\n\n", limit, theta(limit), theta(limit) - pi); limit=10; printf ("\nNumber of terms = %d\nTheta = %lf\nDifference between theta and pi = %lf\n\n", limit, theta(limit), theta(limit) - pi);
Another thing, when I run what I have so far into the compiler, an error comes up saying that my printf statement is undefined. I think this is an error with my compiler, but I'm not positive. If anyone could verify this for me it would be greatly appreciated. Using Bloodshed Dev C++In this problem you will build a main function, that acts as a test driver for your theta (Θ) function.
In the figure in the book for problem 50, theta (Θ) is used for the approximation of pi (Π).
Make the return type from the theta function a double, the value of theta.
Make the parameter of the theta function an int, the number of terms to be used in the approximation.
Call the theta function from main two times.
The first time, pass the integer 5 to request 5 terms in the approximation.
The second time, pass the integer 10 to request 10 terms in the approximation.
In the main function print a neat listing of the results.
First print the value of pi (which is approximatly 3.141592653589793),
Then print the following for each of the two passes:
* The number of terms
* The values calculated for theta
* The difference between the values of theta and pi