-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC++ Loop Nested loop factorial.cpp
More file actions
44 lines (33 loc) · 1.1 KB
/
C++ Loop Nested loop factorial.cpp
File metadata and controls
44 lines (33 loc) · 1.1 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
/**
[AUTHOR]: Saddam Arbaa
[Email] : <saddamarbaas@gmail.com>
Nested Loops examples in C++
write c++ program that calculate factorial of numbers
from 1 to N and N will be entered by user
*/
#include <iostream>
using namespace std;
/* Driver program to test factorial of numbers */
int main()
{
int N; // number will enter by user
float fact ; // variable for factorial
//asking user to enter the number
cout << "please Enter number :";
cin >> N;
// outer loop
for (int i = 1; i <= N; i++)
{
fact = 1; //factorial start from 1 because we need count for each number from 1 to that number
// inner loop to calculate for each number
for (int j = 1; j <= i ; j++)
{
fact = fact * j; // calculation factorial for each number
// cout << fact << "\t"; // only was for testing
}
// print factorial for each number
cout << "factorial of " << i << " = "<<fact;
cout <<"\n";
}
return 0;// signal to operating system everything works fine
}/** End of main function */