[MM31-易] Factorial Number
Problem Description
Write a program that prompts the user to input a number 'n', and then print the i-th factorial number defined as follows:
F(0) = 1, F(1) = 1, F(2) = 1x2, and F( n ) =1x2x3x…x(n-2)x(n-1)xn
Input File Format
The input consists of M cases. The first line of the input contains only one positive integer M, followed by M cases. Each case consists of exactly one line with one integer n, 0 ≤ n ≤ 12.
Output Format
For each case, print exactly one line containing only one integer: the i-th factorial number.
Example
Write a program that prompts the user to input a number 'n', and then print the i-th factorial number defined as follows:
F(0) = 1, F(1) = 1, F(2) = 1x2, and F( n ) =1x2x3x…x(n-2)x(n-1)xn
Input File Format
The input consists of M cases. The first line of the input contains only one positive integer M, followed by M cases. Each case consists of exactly one line with one integer n, 0 ≤ n ≤ 12.
Output Format
For each case, print exactly one line containing only one integer: the i-th factorial number.
Example
Sample Input: | Sample Output: |
3 1 3 5 | 1 6 120 |
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <stdio.h>
- #include <ctype.h>
- #include <cmath>
- using namespace std;
- int main() {
- // [MM31-易] Factorial Number
- string N, Num;
- getline(cin, N);
- int n = stoi(N);
- for(int i = 0;i < n;i++)
- {
- getline(cin, Num);
- int num = stoi(Num);
- int re = 1;
- for(int j = num;j > 0;j--)
- {
- re = re * j;
- }
- cout << re << endl;
- }
- return 0;
- }
沒有留言:
張貼留言