Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Sandbox

Obligatory factorial challenge

+3
−0

It looks like we don't have a simple factorial challenge yet, so here's one.

Task

Given a non-negative number, output the factorial of that number ($n!$). The factorial of a number can be defined as such:

$$f(0)=1$$ $$f(n)=n \times f(n-1)$$

Test cases

Input! = Output
0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
10! = 3628800

Rules

  • The default rules for input and output apply.
  • This is [code-golf], so the shortest code in bytes wins!
  • Should I delete this draft or put it on hold? Razetime has pointed out that we don't want too many challenges similar to those Somewhere Else, but I thought this'd be a good challenge for beginners.
History
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

Small note (3 comments)