Go Program to check a number is a strong number or not

In this program, You will learn how to check a number is a strong number or not in Go.


for <condition>{
   //statement
}

go program to check a number is a strong number or not

Example: How to check a number is a strong number or not in Go

package main

import "fmt"

func main() {

	var n, r, f int
	fmt.Print("Enter a number:")
	fmt.Scan(&n)
	t := n
	s := 0

	for n > 0 {
		r = n % 10
		f = 1
		for i := 1; i <= r; i++ {
			f = f * i
		}
		s = s + f
		n = n / 10
	}

	if s == t {
		fmt.Println("It's a strong number:", t)
	} else {
		fmt.Println("It's not a strong number:", t)
	}

}

Output:

Enter a number:145
It's a strong number: 145