Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

to calculate sum of the series :(1/1!)+(2/2!)+(3/3!)+(4/4!)+............+(n/n!)

0 votes
asked Feb 20, 2018 by anonymous

2 Answers

0 votes
answered Feb 20, 2018 by yash maurya
#include<stdio.h>
#include<conio.h>
int main()
{
int n;
float sum = 0,d,fact =1,j,i;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=1;
for (j=1;j<=i;j++)
{
fact=fact*j;
}
d=(float)i/(float)fact;
sum=sum+d;
}
printf("sum = %.2f", sum);
getch();
return 0;
}
0 votes
answered Feb 24, 2018 by anonymous

#include <stdio.h>

int main(){
    const int N=10000;
   
    double sum = 0;
    double fac = 1; // 0! = 1
    for(int n=1; n<=N; n++){
        fac *= n;
        sum += n/fac;
    }
   
    printf("1/1!+2/2!+3/3!+...+N/N! = %f ; (with N=%d)", sum, N);
    return 0;
}

commented Feb 24, 2018 by anonymous
N/N! = 1/(N-1)!                  ... this would be better
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...