forked from Shubhamlmp/Programming-Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
34_Factorial.cpp
19 lines (18 loc) · 1.15 KB
/
34_Factorial.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//Given a number N. Print the factorial of number N.
#include <iostream> //iostream is a header file which contains basic input/output functions.
#include <iomanip> //iomanip is a header file which contains functions for input/output manipulations.
#include <cmath> //cmath is a header file which contains mathematical functions.
int main() {
int t; //Declaring variable t as integer.
cin >> t; //Taking input of t.
while(t--) { //Looping t times.
int n; //Declaring variable n as integer.
cin >> n; //Taking input of n.
long long int fact = 1; //Declaring variable fact as long long int and initializing it with 1.
for(int i = 2; i <= n; i++) //Looping from 2 to n.
fact *= i; //Multiplying fact with i.
cout << fact << endl; //Printing fact.
}
return 0; //Return 0 to indicate that the program ended successfully.
//End of program
}