-->

Facebook

Jasper Roberts - Blog

Monday, October 6, 2014

Write a program to print 1+1/2+1/3+1/4+....+1/N series.

#include<conio.h>
#include<stdio.h>

void main()
{
double i, n, sum = 0;
clrscr();

printf("enter the number:");
scanf("%lf",&n);

            for(i=1;i<=n;i++)
            {
                        sum = sum + (1/i);

                        if(i==1)
                                    printf("\n 1 + ");
else if(i==n)
printf("(1/%lf)",i);
else
printf("(1/%lf) + ",i);
}

printf("\n = %.2lf",sum);

 getch();

}

2 comments: