0
677views
Write a program to calculate summation of series.

$$ \frac{1}{1!} + \frac{2}{2!} + \frac{3}{3!} + ... + \frac{n}{n!}$$

Subject : Structured Programming Approach

Title : Control Structures

Difficulty : Medium

1 Answer
0
0views

Program:

#include <stdio.h>
#include <conio.h>

int main()
{
    int n,i,j;
    long f;
    float sum;
    clrscr();
    sum = 1; f = 1;
    printf("\n\n\t Sum of 1/1! + 2/2! + ... + n\n!");
    printf("\n\n\t p1. Enter n");
    scanf("%d", &n);

    for(i=2; i<=n; i++)
    {
        for(j=1; j<=i; j++) {
            f = f * j;
        }
        sum = sum + i / (float)f;
    }

    printf("\n\n\t Sum = %f", sum);
    getch();

    return 0;
}
Please log in to add an answer.