The Program in C to print 1 / 1! + 2 / 2! +3 / 3! ….n is given below:
#include <stdio.h>
int main() {
int n, i;
double sum = 0;
printf("Enter the value of n: ");
scanf("%d", &n);
for (i = 1; i <= n; i++) {
double factorial = 1;
int j;
for (j = 1; j <= i; j++) {
factorial *= j;
}
sum += (double) i / factorial;
}
printf("The sum of the series is: %lf", sum);
return 0;
}
Output:
Enter the value of n: 56
The sum of the series is: 2.718282
Pro-Tips💡
This program prompts the user to enter the value of n and then calculates the sum of the series using a nested loop.
The outer loop iterates from 1 to n, and the inner loop calculates the factorial of the current value of the outer loop variable.
The program then adds the result of (i/factorial) to the sum and prints the final result.