I have tried several to identify why, but I could not do so, so if anyone get identified please let me know..
#include <stdio.h>
int main()
{
int i,n=1;
float div=0,sum=0,j=1;
for(i=1;i<=7;i++)
{
j=1;
for(n=1;n<=i;n++)
{
j=j*n;
}
div=i/j+div;
}
printf(" %f",div);
return 0;
}
actually it is a program to display " Write a program to add first seven terms of the following series using For-Loop :
(1/1!)+(2/2!)+(3/3!)+………… "
By running the above program we get result as 2.72 which is correct one. but if we run code below
#include <stdio.h>
int main()
{
int i,n=1,j=1;
float div=0,sum=0;
for(i=1;i<=7;i++)
{
j=1;
for(n=1;n<=i;n++)
{
j=j*n;
}
div=i/j+div;
}
printf(" %f",div);
return 0;
}
but what actually done is changing j=1
from int to float and vice versa. but the result is varying..