bogdan2004333

Untitled

Oct 7th, 2022 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <locale.h>
  3. #include <math.h>
  4.  
  5. float factorial(float n) {
  6.     float res=1;
  7.     for(float i=1;i<=n;i++)
  8.         res*=i;
  9.         return res;
  10.  
  11. }
  12.  
  13. int main() {
  14.     setlocale(0, "");
  15.     float Y=0;
  16.     printf("%s %17s %14s %11s","x","Y","S","N");
  17.     fflush(stdout);
  18.     for(float x=0;x<=1;x+=0.2){
  19.         float S=0;
  20.         Y =cos(1-x*4);
  21.         float delta=1;
  22.         int n=0;
  23.         while(delta>0.000001) {
  24.             S += pow(-1, n) * pow(1 - x * 4, 2 * n) / factorial(2 * n);
  25.             n++;
  26.             delta = fabs(S - Y);
  27.  
  28.         }printf("\n%f %14.6f %14.6f       %d", x, Y, S, n);
  29.     }
  30.  
  31.  
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment