C program to determine and print the sum a harmonic series

Written by siddhartha. Posted in Misc

Source Code

/*************************************************************************************/
/*  C program to determine and print the sum of the following harmonic series for    */
/*  a given value of n: 1+1/2+1/3+………………+1/n                                         */
/*  Download more programs at http://sourcecode4u.com/                               */
/*************************************************************************************/
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
float i, sum, t;
printf("1+1/2+1/3+......+1/n\n");
printf("Enter the value of n\n");
scanf("%d",&n);
sum=0;
for(i=1;i<=n;i++)
{
t=1/i;
sum=sum+t;
}
printf("%f",sum);
getch();
}

Out Put

BLOG COMMENTS POWERED BY DISQUS