0

Write a c++ programe to calculte value of Y from "Y=1/1!+2/2!+3/3!+.......+n/n!

12th Jan 2017, 11:39 AM
Ahmed Elgendy
Ahmed Elgendy - avatar
3 Respostas
0
#include<iostream> #include"stdafx.h" double factorial(int x) { int fact = 1; for(int i = 1; i <= x; i++) { fact *= i; } return fact; } int main() { int n; double Y = 0; using namespace std; cout << "Enter a number :" << endl; cin >> n; for(int i = 1; i <= n; i++) { Y += (i/factorial(i)); } cout << "Y = " << Y << endl; return 0; }
12th Jan 2017, 11:56 AM
Salman Momin
Salman Momin - avatar
0
Not run
12th Jan 2017, 12:02 PM
Ahmed Elgendy
Ahmed Elgendy - avatar
0
I've tested it in visual studio...
12th Jan 2017, 12:16 PM
Salman Momin
Salman Momin - avatar