Thursday, 27 October 2011

C program to find the sum of the series: 1+(1/2)+(1/3)+...n terms

WRITE A C PROGRAM TO FIND THE SUM OF THE FOLLOWING SERIES:
1+(1/2)+(1/3)+....N TERMS



#include<stdio.h>
#include<conio.h>
void mian()
{
  int n,i;
  float t,s=0;
  printf("Enter the number of terms:");'
  scanf("%d",&n);
  for(i=1;i<=n;i++)
 {
   t=1.0/i;
   s=s+t;
 }
 printf("The sum is: %f",s);
 getch();
}


Output:
   Enter the number of terms:2
   The sum is: 1.500000

No comments:

Post a Comment