0
Write a c++ programe to calculte value of Y from "Y=1/1!+2/2!+3/3!+.......+n/n!
3 ответов
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;
}
0
Not run
0
I've tested it in visual studio...