Monday, January 6, 2014

PRINT SUM OF THE GIVEN SERIES

/*print sum of    1   -  (1/2)  +   (1/3) - (1/4)....*/



#include<stdio.h>
#include<conio.h>
void main()
{
int i,N,sign=1;
float e=1;
float d,sum=0;
clrscr();
printf("enter N\n");
scanf("%d",&N);
for(i=1;i<=N;i++)
{
  d=(e/i)*sign;
  printf("d=%f\n",d);
  sum=sum+d;
  sign*=(-1);


}
printf("result=%f\n",sum);
getch();
}

No comments:

Post a Comment