Algorithm


Problem Name: beecrowd | 1153

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1153

Simple Factorial

 

Adapted by Neilor Tonin, URI Brazil

Timelimit: 1

Read a value N. Calculate and write its corresponding factorial. Factorial of N = N * (N-1) * (N-2) * (N-3) * ... * 1.

 

Input

 

The input contains an integer value N (0 < N < 13).

 

Output

 

The output contains an integer value corresponding to the factorial of N.

 

 

 

Input Sample Output Sample

4

24

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include<bits/stdc++.h>

using namespace std;

int main(){
    int n;
    cin >> n;
    int ans = 1;
    for (int i = 1; i  < = n; i++){
        ans *= i;
    }
    cout << ans << endl;
    return 0;
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
4

Output

x
+
cmd
24

#2 Code Example with Java Programming

Code - Java Programming


import java.io.IOException;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) throws IOException{
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int ans = 1;
        for (int i = 1; i  < = n; i++){
            ans *= i;
        }
        System.out.println(ans);
    }
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
4

Output

x
+
cmd
24

#3 Code Example with Javascript Programming

Code - Javascript Programming


var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');

var n = parseInt(lines.shift());

var ans = 1;
for (let i = 1; i  < = n; i++){
    ans *= i;
}
console.log(ans);
Copy The Code & Try With Live Editor

Input

x
+
cmd
4

Output

x
+
cmd
24

#4 Code Example with Python Programming

Code - Python Programming


n = int(input())

ans = 1

for i in range(1, n+1):
    ans *= i

print(ans)
Copy The Code & Try With Live Editor

Input

x
+
cmd
4

Output

x
+
cmd
24
Advertisements

Demonstration


Previous
#1152 Beecrowd Online Judge Solution 11152Dark Roads - Solution in C, C++, Java, Python and C#
Next
#1154 Beecrowd Online Judge Solution 1154 Ages Solution in C++, Java, Js and Python