Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <locale.h>
- #include <math.h>
- float factorial(float n) {
- float res=1;
- for(float i=1;i<=n;i++)
- res*=i;
- return res;
- }
- int main() {
- setlocale(0, "");
- float Y=0;
- printf("%s %17s %14s %11s","x","Y","S","N");
- fflush(stdout);
- for(float x=0;x<=1;x+=0.2){
- float S=0;
- Y =cos(1-x*4);
- float delta=1;
- int n=0;
- while(delta>0.000001) {
- S += pow(-1, n) * pow(1 - x * 4, 2 * n) / factorial(2 * n);
- n++;
- delta = fabs(S - Y);
- }printf("\n%f %14.6f %14.6f %d", x, Y, S, n);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment