You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
569 B
C

/*
* C Program to find the Sum of Series 1 + 1/2 + 1/3 + 1/4 + ... + 1/N
*/
#include <stdio.h>
void main()
{
double number, sum = 0, i;
printf("\n enter the number ");
scanf("%lf", &number);
for (i = 1; i <= number; i++)
{
sum = sum + (1 / i);
if (i == 1)
printf("\n 1 +");
else if (i == number)
printf(" (1 / %lf)", i);
else
printf(" (1 / %lf) + ", i);
}
printf("\n The sum of the given series is %.2lf", sum);
}