Skip to content

Commit 8364624

Browse files
committed
adding new files
1 parent c36174d commit 8364624

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

recursivefunction.go

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
// This line indicates that this is the main package, which is required for a Go program.
12
package main
23

4+
// This line imports the fmt package, which provides functions for formatting and printing text.
35
import "fmt"
46

57
func factorial(n int) int {
@@ -12,6 +14,8 @@ func factorial(n int) int {
1214
return n * factorial(n-1)
1315
}
1416

17+
// This is the factorial() function, which takes an integer n as input and returns the factorial of that number. It uses recursion to calculate the factorial.
18+
1519
func main() {
1620

1721
var n int
@@ -31,3 +35,5 @@ func main() {
3135
fmt.Printf("\nFactorial is %d", result)
3236

3337
}
38+
39+
// This is the main() function, which is the entry point for the program. It prompts the user to enter a number, scans that number from the standard input, and checks if the number is negative. If the number is negative, it prints an error message. Otherwise, it calls the factorial() function with the entered number as input, stores the result in a variable called result, and prints the result to the console.

0 commit comments

Comments
 (0)