You Are The Visitor Number

Friday, March 14, 2008

/* Program to evaluate sum of series S=1+1/2+1/3...+1/N */

I think in this case no introduction is required. I have taken output as float because naturally it will be float. Taking output as int the program will work but don't give accurate answers.

/* Program to evaluate sum of series S=1+1/2+1/3...+1/N */

/* Author Mitochondria Technologies Inc. */

#include<stdio.h>

#include<conio.h>

void main()

{

int i,n;

float sum;

clrscr();

printf("\n Enter the value to N : ");

scanf("%d",&n);

sum=0;

for(i=1;i<=n;i++)

sum=sum+1.0/i;

printf("\n Sum of series : %f",sum);

getch();

}

No comments: