Golang - Demonstrate the concept of head recursion Code Example

The code for Demonstrate the concept of head recursion

package main

import (
	"fmt"
)

func print_num(n int) {
	if n > 0 {
		print_num(n-1)
		fmt.Println(n)
	}
}

// main function
func main() {
	print_num(10)
}



/*
Output:
1
2
3
4
5
6
7
8
9
10
*/
Code by IncludeHelp, on March 1, 2023 07:05

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.