Answer to Question #4287 in C++ for kuldeep

Question #4287
Write a c++ program to sum the sequence
1+ 1/1! + 1/2! + 1/3! + .......
1
Expert's answer
2011-10-07T09:25:05-0400

#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";
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS