CPP

#include <iostream>
using namespace std;
const int MAXSIZE = 10000;
int A[MAXSIZE];
int main(void) {
  int n;
  cin >> n;
  A[0] = 1;
  for(int i = 1;i<=n;i++){
    int carry = 0;
    for(int j = 0;j<MAXSIZE;j++){
      A[j] = A[j]*i + carry;
      carry = A[j] / 10;
      A[j] = A[j] % 10;
    }
  }
  int large;
  for(int k = 10000 - 1;k>=0;k--) {
    if(A[k] != 0) {
      large = k;
      break;
    }
  }
  for(int m=large;m>=0;m--) {
    cout << A[m];
  }
}

JAVA

import java.util.Scanner;
public class Main {
    static int MAXSIZE = 10000;
    static int[] A = new int[MAXSIZE];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        A[0] = 1;
        for(int i = 1;i<=n;i++){
            int carry = 0;
            for(int j = 0;j<MAXSIZE;j++){
                A[j] = A[j] * i + carry;
                carry = A[j] / 10;
                A[j] = A[j] % 10;
            }
        }
        int large = 0;
        for(int k = MAXSIZE - 1;k>=0;k--){
            if(A[k] !=0){
                large = k;
                break;
            }
        }
        for(int m = large;m>=0;m--){
            System.out.print(A[m]);
        }
    }
}
import java.math.BigInteger;
import java.util.*;
 
public class Main {
     public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNext()) {
            int n = in.nextInt();
            BigInteger s = new BigInteger("1");
            for(int i = n; i >= 1; i--)
                s = s.multiply(new BigInteger(String.valueOf(i)));
            System.out.println(s);
        }
    }
}