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.

29 lines
631 B
C

/* Sum of series - Program to calculate sum of series 1/2 + 3/4 + 5/6 + ....... + n terms - May 2013 */
#include <stdio.h>
#include <conio.h>
void main()
{
int i, n ;
float k, s=0 ;
clrscr() ;
printf("Enter n: ") ;
scanf("%d", &n) ;
/* i keeps track of term count , whereas k is used for calculation purpose */
for(i=1, k=1 ; i<=n ; i++, k=k+2)
s=s+ k/(k+1) ;
/* k has to be float in the above expression. If k is int then s will remain zero */
printf("Sum of the required series is %f", s) ;
getch() ;
}
/*
Output :
Enter n: 4
Sum of the required series is 2.958333
*/