Program to calculate sum of series 1 +1/x^1 + 1/x^2 + 1/x^3 ... + 1/x^n terms in C
#include <stdio.h>
#include <math.h>
int main()
{
int x,n,i;
float sum=0;
printf("Enter total number of terms: ");
scanf("%d",&n);
printf("Enter the value of x: ");
scanf("%d",&x);
for(i=1; i<=n; i++){
sum += 1+(1/pow(x,i));
}
printf("Sum of the series: %f\n",sum);
return 0;
}
Output
Enter total number of terms: 5
Enter the value of x: 2
Sum of the series: 5.968750
Program to calculate sum of series 1 +1/x^1 + 1/x^2 + 1/x^3 ... + 1/x^n terms in C
Output
Solution
need an explanation for this answer? contact us directly to get an explanation for this answer