Saturday, April 3, 2021

Factorial Using Functions in Go

 A simple program that I wrote to solve a factorial value of a given number using a function and recursion concepts in go programming language.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com



Program Listing

/* function_recursion.go
Prof. Jake R. Pomperada, MAED-IT, MIT
www.jakerpomperada.com / www.jakerpomperada.blogspot.com
jakerpomperada@gmail.com
March 31, 2021  Saturday 10:18 PM
Bacolod City
*/

package main

import "fmt"

func factorial_solve(num intint {
    if num == 1 || num == 0 {
        return num
    }
    return num * factorial_solve(num-1)
}

func main() {
    fmt.Printf("\n")
    fmt.Print("\tRecursion Using Function in Go\n\n")
    fmt.Printf("\t %d\n", factorial_solve(3))
    fmt.Printf("\t %d\n", factorial_solve(4))
    fmt.Printf("\t %d\n", factorial_solve(5))
    fmt.Printf("\t %d\n", factorial_solve(6))
    fmt.Printf("\t %d\n", factorial_solve(7))
    fmt.Printf("\n")
    fmt.Printf("\tEnd of Program")
    fmt.Printf("\n")
}



No comments:

Post a Comment