Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- void printRow(double x, double formula, double result) {
- printf("x = % .1lf |\t\t", x);
- printf("formula = % .6lf |\t\t", formula);
- printf("sequence = % .6lf\n", result);
- printf("----------------------------------------------------------------------------\n");
- }
- long factorial( long a )
- {
- return 0 == a ? 1 : ( a * factorial( a - 1 ) );
- }
- int main() {
- double step, start, end;
- printf("Enter step, start and end of the line: ");
- scanf("%lf %lf %lf", &step, &start, &end);
- if(fabs(start) > 1 || fabs(end) > 1 || step > fabs(start-end)) {
- printf("Valid bounds: -1 to 1, don't make step too big!\n");
- return 0;
- }
- double x = start;
- while(x < end) {
- double formula = pow(1+x,0.5);
- double result = 0;
- for(int n = 0; n<10; n++) {
- result += ((pow(-1,n)*factorial(2*n))/((1-2*n)*pow(factorial(n),2)*pow(4,n)))*pow(x,n);
- }
- printRow(x, formula, result);
- x += step;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement