Friday, April 26, 2013

Sum the series:Sum=(x2)1+(x2)2+(x2)3+.......+(x2)n

Write a C program to Calculate the below Series. The Value of x and n must take from input terminal.
Sum=(x2)1+( x2 )2+( x2 )3 + ….  +  (x2)n 




 #include<stdio.h>
main()
{
    int i,n,x,c,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++)
    {
        c=x*x;
        r*=c;
        sum+=r;
    }
    printf("\nThe sum is:");
    printf("%d\n",sum);
}

No comments:

Post a Comment