rendered paste body#include <stdio.h>
#include <math.h>
#define PI 3.1415927
long int factorial(int n)
{
if (n<=1)
return(1);
else
n=n*factorial(n-1);
return(n);
}
int main (void)
{
int answer, x, expon;
float sums, first_term, error, next_term;
double y = 2/(sqrt(PI));
long int factorial(int n);
printf("Enter a number :");
scanf("%i",&answer);
if( answer == 0) { //if answer is 0 the error is 0
printf("The error is : 0 \n \n");
} //if block ends
else {
for (x = 1; x <= 5; ++x){
if(x % 2 != 0){
answer = answer *-1;
}
else{
answer = answer * 1;
}
expon = 2 * x + 1;
first_term = -1*( pow(answer,1) )/( 1 * factorial(0) );
sums = first_term;
next_term = (pow(answer,expon) )/ (expon * factorial(x) );
sums = sums + next_term;
error = y * sums;
} // for block ends for factorial
printf("Error = %f \n", error);
}
return 0;
}