0

HELP

#include <iostream> using namespace std; int main() { long double fac=1, sum=0; int i,j; for(i=2; i<=50; i++) { for(j=1; j<i; j++) { fac*=i; sum+=(j/fac); } } cout << sum ; return 0; } is this code correct for the expression 1/2!+2/3!+.....+49/50! ?

3rd Jul 2018, 5:30 PM
Aveek Bhattacharyya
Aveek Bhattacharyya - avatar
1 Answer
0
I think you calculate the factorial in the wrong way, also you never reset "fac", resulting in it keeping its value all the time, and I think the addition to the sum should be done once per iteration, e.g. after the second for-loop. For reference: https://code.sololearn.com/cpPEjwJQD05r/?ref=app
3rd Jul 2018, 6:39 PM
Shadow
Shadow - avatar