This is my first ever program. I have struggled big time and its token so long my university lab is closed, can someone please check this over and maybe even correct some parts. I would be so happy if someone could. Thanks
The assignment is to use sharps approximation formula to calculate PI, which is a continous formula until n = k. The second part is to use M_PI and take away the approxiamtion formula, and print both.
The assignment is to use sharps approximation formula to calculate PI, which is a continous formula until n = k. The second part is to use M_PI and take away the approxiamtion formula, and print both.
Code:
#include <stdio.h> #include <math.h> int main (void) { float part1, part2, part3, numerator, n; int k; printf ("Please input number of iterations"); scanf("%d",&n); for (k = 0; k <= n; k++); { if (k%) numerator = -1.0; else numerator =1.0; part1 += numerator / (3pow k)* ((2* k) +1); part2 = 3.464101615 * part1 part3 = M_PI - part2 printf ("%f, %f", part2, part3); } }
Comment