Tuesday, April 23, 2013

Sum the Series: Sum = x + x2 + x3 +…. + xn

Write a C program to Calculate the below Series. The Value of x and n must take from input terminal.

  Sum = x + x2 + x3 +…. +  xn




#include<stdio.h>
main()
{
    int i,n,x,r=1,sum=0;
    printf("Enter the value of X:");
    scanf("%d",&x);
    printf("\nEnter the value of range for series:");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        r=r*x;
        sum+=r;
    }
    printf("\nThe sum is:");
    printf("%d\n",sum);
}
 

No comments:

Post a Comment