Saturday, June 13, 2015

series(1/1 + 1/2 + 1/3 + 1/4 + . . . + 1/n----A.P)

#include<stdio.h>
///1/1 + 1/2 + 1/3 + 1/4 + . . . + 1/n
int main()
{

    float num,i,sum=0;

    printf("Please enter any number:\n");
    scanf("%f", &num);

    for (i=1;i<=num;i++)
    {
        sum=sum +(1/i);
        if (i==1)
            printf("\nThe series is: 1+");
        else if (i==num)
            printf("(1/%.0f)\n",i);
        else
            printf("(1/%.0f)+",i);
    }
    printf("\nThe sum of the series is:%.2f\n", sum);
    return 0;
}

No comments:

Post a Comment