Tuesday, April 23, 2013

Sum the series: sum= x+2x+3x+.......+xn

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

Sum = x+2x+3x+.......+xn

 


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

   printf("\nThe sum is:);
    printf("%d\n",sum);
}
 

No comments:

Post a Comment