Question-Write a program to add first seven terms of the following
series using a for loop:
1/1! + 2/2! + 3/3!……
Solution- good question. let's see it's solution.use of functions would make it more clear, but i would follow to the book here.
#include<stdio.h>
int main()
{
int fact=1,i;
float ans=0.0;
for(i=1;i<=7;i++)
{
fact=fact*i;
ans=ans+(i/fact);
}
printf("Answer=%f\n",ans);
return 0;
}
series using a for loop:
1/1! + 2/2! + 3/3!……
Solution- good question. let's see it's solution.use of functions would make it more clear, but i would follow to the book here.
#include<stdio.h>
int main()
{
int fact=1,i;
float ans=0.0;
for(i=1;i<=7;i++)
{
fact=fact*i;
ans=ans+(i/fact);
}
printf("Answer=%f\n",ans);
return 0;
}
No comments:
Post a Comment