forked from Rustam-Z/cpp-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource3.cpp
More file actions
32 lines (29 loc) · 963 Bytes
/
Copy pathSource3.cpp
File metadata and controls
32 lines (29 loc) · 963 Bytes
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
// Practical Lab Assignment-7(Week 9)
// ID:U1910049 Name: Rustam Zokirov
// Program to sum the series up to n
#include <iostream>
#include <math.h>
using namespace std;
double qwerty(double n, double sum, double fact)
{
for (int i = 1; i <= n; i++)
{
fact = fact * i; // calculating the factorial of the numbers
sum += (pow(i, i) / (fact)); // executing the sum of numbers
} //"pow" is raising 'i' to power 'i'
return sum; //
} // end function qwerty
int main()
{
double n;
double sum = 0;
double fact = 1;
cout << "Please ebter the number: "; // outputing and inputing the number
cin >> n;
if (n > 0) // the program will calculate the sum when numbers is positive
cout << "Sum is: " << qwerty(n, sum, fact) << endl; // calling the function qwerty
else // when the number is negative 'else' will work
cout << "INVALID INPUT!" << endl;
system("pause");
return 0;
} // ending the program successfully