Hello,I need help with the following series (sorry I forgot what its called..)
1/1! - 2/2! + 3/3! -4/4!....upto n terms
Here's my program :
#include<conio.h>
#include<stdio.h>
#include<float.h>
void main()
{
float com=0,j=0,j1=0,ans=0; //variable decl of float type
int tillw,i,no=0,fac1=1,fac=1,f1,f2; //variable decl of int type
clrscr();
printf("\n\n\t\t *********************************");
printf("\n\t\t ---------------------------------");
printf("\n\n\t\t SERIES");
printf("\n\n\t\t ---------------------------------");
printf("\n\t\t *********************************");
printf("\n\n\n\n\t\t Enter till where you want : ");
scanf("%d",&tillw);
flushall(); //accept no. from user
for(i=1;i<=tillw;i++)
{
no=no+1;
ans=no%2;
if(ans!=0)
{
//addition part of series
for(f1=1;f1<=no;f1++)
{
fac=fac*f1;
} //find factorial
j=no/fac;
com=com+j;
}
else
{
//subtraction part of series
for(f2=1;f2<=no;f2++)
{
fac1=fac1*f2;
} //find factorial
j1=no/fac1;
com=com-j1;
}
//printf("\n\n\t\t The answer is : %0.2f",com);(for testing answer in each step)
} //main for-loop ends..
printf("\n\n\t\t The answer is : %f",com); //prints final answer
getch();
} //void-main ending..
So now my problem is,whatever input I give the answer is always 0.00
PS:Realized that it gives correct answer till 2,but after that whatever the input it gives 0.00 as the answer