Tuesday, April 23, 2013

Sum the Series: Sum=x1 + x1/2 + x1/3 + …. + x1/n

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

Sum=x1 + x1/2 + x1/3  + ….  +  x1/n 



#include<stdio.h>
#include<conio.h>
main()
{
    int i,x,n,j;
    float sum=0.0,a=1.0,r,y;
    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++)
    {
        y=a/i;
        r=x*y;
        sum=sum+r;
    }
    printf("\nThe sum is:");
    printf("%f\n",sum);
}
 

No comments:

Post a Comment