Plaese solve this in C programming! (also the extra credit question.) In mathema
ID: 671756 • Letter: P
Question
Plaese solve this in C programming! (also the extra credit question.)
In mathematics, a Taylor series is a representation of a function as an infinite sum of terms that are calculated from the values of the function's derivatives at a single point. The Taylor series of a real or complex-valued function f(x) that is infinitely differentiable at a real or complex number a is the power series f(x) = y, fn(a) f'(a) 1! f"(a) 2: af"(a) 3! n=0 One such special series is given below N oo, for all x , Your program should 1. Accept a double data type value for x 2. Display the result for the e (left hand side (LHS) of the above equation) 3. Using a loop and increasing the order of N (begin at 1, work your way up, by a factor of 2, to 1024), create a table of the values for the summation series (right hand side(RHS) of the above equation), difference between the result of the function (LHS) and the summation series (RHS) (Extra credit (10 points)): Using the other two kinds of loops (if you were using while loop in your first code, then use do-while and for loops) finish the same work. These should be finished in different source codes, which means you will have three source codes to upload. For example, the first one is solved by using while loop, the second one is solved by using for loop and third using do-while loopExplanation / Answer
// program using for loop
#include <stdio.h>
#include <Math.h>
int fact(int n){
int i,f=1;
for(i=1;i<=n;i++)
f=f*i;
return f;
}
int main()
{
double x,ex;
int i=1,N=1024,n,k=1;
double sum,diff;
printf(" Enter the value of x:");
scanf("%lf",&x);
ex=exp(x);
printf("You have entered x as:%lf. The value of e power x is:%lf",x,ex);
for(i=1;i<=N;i=pow(2,k))
{
sum=0.0;
for(n=0;n<=i;n++)
{
sum=sum+(pow(x,n)/fact(n));
//printf(" %lf",sum);
}
diff=ex-sum;
printf(" N=%d sum of series=%lg diff=%lf",i,sum,diff);
k++;
}
return 0;
}
// program using while loop
#include <stdio.h>
#include <Math.h>
int fact(int n){
int i=1,f=1;
do
{
f=f*i;
i++;
}while(i<=n);
return f;
}
int main()
{
double x,ex;
int i=1,N=1024,n,k=1;
double sum,diff;
printf(" Enter the value of x:");
scanf("%lf",&x);
ex=exp(x);
printf("You have entered x as:%lf. The value of e power x is:%lf",x,ex);
do
{
sum=0.0;
n=0;
do
{
sum=sum+(pow(x,n)/fact(n));
n++;
}while(n<=i);
diff=ex-sum;
printf(" N=%d sum of series=%lg diff=%lf",i,sum,diff);
k++;
i=pow(2,k);
}while(i<=N);
return 0;
}
// program using do-while loop
#include <stdio.h>
#include <Math.h>
int fact(int n){
int i=1,f=1;
while(i<=n)
{
f=f*i;
i++;
}
return f;
}
int main()
{
double x,ex;
int i=1,N=1024,n,k=1;
double sum,diff;
printf(" Enter the value of x:");
scanf("%lf",&x);
ex=exp(x);
printf("You have entered x as:%lf. The value of e power x is:%lf",x,ex);
while(i<=N)
{
sum=0.0;
n=0;
while(n<=i)
{
sum=sum+(pow(x,n)/fact(n));
n++;
}
diff=ex-sum;
printf(" N=%d sum of series=%lg diff=%lf",i,sum,diff);
k++;
i=pow(2,k);
}
return 0;
}