Advertisement
Cool_boy21

Untitled

Sep 9th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. void printRow(double x, double formula, double result) {
  5.     printf("x = % .1lf |\t\t", x);
  6.     printf("formula = % .6lf |\t\t", formula);
  7.     printf("sequence = % .6lf\n", result);
  8.     printf("----------------------------------------------------------------------------\n");
  9.  
  10. }
  11.  
  12. long factorial( long a )
  13. {
  14.     return 0 == a ? 1 : ( a * factorial( a - 1 ) );
  15. }
  16.  
  17. int main() {
  18.     double step, start, end;
  19.  
  20.     printf("Enter step, start and end of the line: ");
  21.     scanf("%lf %lf %lf", &step, &start, &end);
  22.  
  23.     if(fabs(start) > 1 || fabs(end) > 1 || step > fabs(start-end)) {
  24.         printf("Valid bounds: -1 to 1, don't make step too big!\n");
  25.         return 0;
  26.     }
  27.     double x = start;
  28.     while(x < end) {
  29.         double formula = pow(1+x,0.5);
  30.         double result = 0;
  31.         for(int n = 0; n<10; n++) {
  32.             result += ((pow(-1,n)*factorial(2*n))/((1-2*n)*pow(factorial(n),2)*pow(4,n)))*pow(x,n);
  33.         }
  34.         printRow(x, formula, result);
  35.         x += step;
  36.     }
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement