-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC++ Function Factorial .cpp
More file actions
38 lines (29 loc) · 918 Bytes
/
C++ Function Factorial .cpp
File metadata and controls
38 lines (29 loc) · 918 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
33
34
35
36
37
38
/**
[PROGRAM] : C++ Functions
[AUTHOR] : Saddam Arbaa
[Email] : <saddamarbaas@gmail.com>
Factorial Program using Loop */
#include <iostream>
using namespace std;
// Function declaration
int Fact(int);
// the main Function
int main()
{
int n, Factorial; //variable declaration
cout << "Enter number N:"; // asking user input
cin >> n;
Factorial = Fact(n); // call the function
// print the result
cout <<"the Factorial of " << n << " is : " << Factorial;
return 0;// signal to operating system everything works fine
}/** End of main function */
/** function to calculate Factorial of Number */
int Fact(int n)
{
int i, f; //variable declarations
f = 1; //initialize f by 1
for(i = n; i>=1; i--) // loop from given n to 1
f = f * i; // calculate Factorial
return f; // return the Factorial
}/** End of fact */