-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC++ Math series factorial Exercis .cpp
More file actions
58 lines (41 loc) · 1.13 KB
/
C++ Math series factorial Exercis .cpp
File metadata and controls
58 lines (41 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
[AUTHOR] : Saddam Arbaa
[Email] : <saddamarbaas@gmail.com>
write program to calculate the flowing math series
y = 1 + x/1! + x^2/2! + x^3/3! + X^4/4!+ .........x^N/N!
and N will be entered by user
Reference :
https://youtu.be/_vTWN2iXUxY
*/
#include <iostream>
#include <math.h> // include math function
using namespace std;
// the Driver Code
int main()
{
int i, j, N ;
float factorial,y,x ;
/*let say x=3 for example*/
x =3;
/*set y by 1*/
y = 1.0;
/*read value of N*/
cout << "Enter the value of N: ";
cin >> N;
/*calculate the series*/
for(i = 1; i < N; i++)
{
/*set factorial by 1*/
factorial = 1.0;
for(j = 1; j <= i; j++)
{
// calculate factorial
factorial = factorial * j;
} /** End of inner loop*/
// calculate y value
y = y + pow(x,i) / factorial;
}/** End of outer loop*/
/*print the result*/
cout << "Result of the series is: " << y << endl;
return 0;// signal to operating system everything works fine
}/** End of main function */