Previous
0 / 18
Module DEMO-32-90DEMO-C-32

Factorial

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

Write a function int factorial(int n) that returns the factorial of n.

n! = n * (n-1) * ... * 1.

0! = 1.

Input Format

A non-negative integer.

Output Format

The factorial value.

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
5
120
5! = 120.
Sample #2
Public sample
0
1
0! = 1.
Sample #3
Public sample
3
6
3! = 6.

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings