Write an iterative function that, given a natural *n*, returns its factorial *n*!.

**Interface**

C++ | int factorial(int n); |

C | int factorial(int n); |

Java | public static int factorial(int n); |

Python | factorial(n) # returns int |

factorial(n: int) -> int |

**Precondition**

Assume 0≤ *n* ≤ 12.

**Observation**
You only need to submit the required procedure;
your main program will be ignored.

Public test cases

**Input/Output**

factorial(0) → 1

factorial(1) → 1

factorial(2) → 2

factorial(3) → 6

factorial(4) → 24

factorial(1) → 1

factorial(2) → 2

factorial(3) → 6

factorial(4) → 24

Information

- Author
- Jordi Petit
- Language
- English
- Translator
- Carlos Molina
- Original language
- Catalan
- Other languages
- Catalan
- Official solutions
- C C++ Java Python
- User solutions
- C C++ Java PHP Python