Skip to content

Commit 62c2c90

Browse files
authored
Added solution to Problem 34 Factorial
1 parent 75ed6a2 commit 62c2c90

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

C++/34_Factorial.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//Given a number N. Print the factorial of number N.
2+
3+
#include <iostream> //iostream is a header file which contains basic input/output functions.
4+
#include <iomanip> //iomanip is a header file which contains functions for input/output manipulations.
5+
#include <cmath> //cmath is a header file which contains mathematical functions.
6+
int main() {
7+
int t; //Declaring variable t as integer.
8+
cin >> t; //Taking input of t.
9+
while(t--) { //Looping t times.
10+
int n; //Declaring variable n as integer.
11+
cin >> n; //Taking input of n.
12+
long long int fact = 1; //Declaring variable fact as long long int and initializing it with 1.
13+
for(int i = 2; i <= n; i++) //Looping from 2 to n.
14+
fact *= i; //Multiplying fact with i.
15+
cout << fact << endl; //Printing fact.
16+
}
17+
return 0; //Return 0 to indicate that the program ended successfully.
18+
//End of program
19+
}

0 commit comments

Comments
 (0)