Go Program to check a number is Armstrong or not

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


func main() {
    //statement
}

Go Program to check a number is Armstrong or not

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

package main

import "fmt"

func main() {

	var n, r, num int
	fmt.Print("Enter a number:")
	fmt.Scan(&n)

	num = n
	rev := 0
	for n > 0 {
		r = n % 10
		rev = rev + r * r * r;
		n = n / 10
	}
	if num == rev {
		fmt.Println("Number is Armstrong:", num)
	} else {
		fmt.Println("Number is not Armstrong:", num)
	}
}

Output:

Enter a number:153
Number is Armstrong: 153