Question #4287

Write a c++ program to sum the sequence

1+ 1/1! + 1/2! + 1/3! + .......

1+ 1/1! + 1/2! + 1/3! + .......

Expert's answer

#include <iostream>

using namespace std;

void main(){

double s = 0;& //that is the sum

double factorial = 1;& //it's the denominator

int i = 1;

cout<<"factorial = "<<factorial<<"\r\n";

for (i=1;i<=10;i++) {& //10 cycles is enough, we'll get 1.71828 at the eighth step

factorial = i*factorial;

s = s + 1/factorial;

cout<<"s = "<<s<<"\r\n";

}

}

## Comments

## Leave a comment