- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Write a Golang program to find the factorial of a given number (Using Recursion)
Examples
Factorial of 5 = 5*4*3*2*1 = 120
Factorial of 10 = 10*9*8*7*6*5*4*3*2*1 =
Approach to solve this problem
- Step 1: Define a function that accepts a number (greater than 0), type is int.
- Step 2: If the number is 1, then return 1.
- Step 3: Otherwise, return num*function(num-1).
Program
package main import "fmt" func factorial(num int) int{ if num == 1 || num == 0{ return num } return num * factorial(num-1) } func main(){ fmt.Println(factorial(3)) fmt.Println(factorial(4)) fmt.Println(factorial(5)) }
Output
6 24 120
- Related Articles
- Java program to find the factorial of a given number using recursion
- C++ Program to Find Factorial of a Number using Recursion
- Java Program to Find Factorial of a Number Using Recursion
- Write a C# program to calculate a factorial using recursion
- C++ program to Calculate Factorial of a Number Using Recursion
- Python Program to find the factorial of a number without recursion
- How to find the Reverse of a given number using Recursion in Golang?
- Swift program to find the reverse of a given number using recursion
- Write a Golang program to find the sum of digits for a given number
- How to Find Factorial of Number Using Recursion in Python?
- How to find the Factorial of a number in Golang?
- Golang Program to Find G.C.D Using Recursion
- Golang Program to find the parity of a given number.
- Java program to calculate the power of a Given number using recursion
- Java program to calculate the GCD of a given number using recursion

Advertisements