Code
Find the sum of the series, take input of x and n.
(x^0/0!)+(x^1/1!)+(x^2/2!)+...+(x^n/n!)
Rate
#include
#include
unsigned int factorial(int n){
if(n==0){
return 1;
}
return n*factorial(n-1);
}
int main() {
int x, n, i=0;
double sum = 0, temp;
printf("Enter the value of x and n:\n");
scanf("%d %d", &x, &n);
while(i<n){
temp=pow(x, i)/factorial(i);
sum+=temp;
i++;
}
printf("The sum of the series is: %.2lf", sum);
return 0;
}
Add comment:
Total 0 comments