Golang - Demonstrate the concept of tail recursion Code Example

The code for Demonstrate the concept of tail recursion

package main

import (
	"fmt"
)

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

func main() {
	print_num(5)
}


/*
Output:
5
4
3
2
1
*/
Code by IncludeHelp, on March 1, 2023 07:03

Comments and Discussions!

Load comments ↻






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