GO Program to Check Armstrong Number
Simple program in go language using for...... loop to check whether an integer (entered by the user) is an Armstrong number. if...else statement used to display final output.
Example
// Golang Program to check Armstrong Number
package main
import "fmt"
func main() {
var number,tempNumber,remainder int
var result int =0
fmt.Print("Enter any three digit number : ")
fmt.Scan(&number)
tempNumber = number
/* A positive integer is called an Armstrong number of order n if
the sum of cubes of each digits is equal to the number itself.
153 = 1*1*1 + 5*5*5 + 3*3*3 // 153 is an Armstrong number.
*/
// Use of For Loop as While Loop
for {
remainder = tempNumber%10
result += remainder*remainder*remainder
tempNumber /=10
if(tempNumber==0){
break // Break Statement used to stop the loop
}
}
if(result==number){
fmt.Printf("%d is an Armstrong number.",number)
}else{
fmt.Printf("%d is not an Armstrong number.",number)
}
}
Most Helpful This Week
How to get first and last element of slice in Golang?
Go program to reading plain text files
Program in Go language to Program to Add Two Matrix Using Multi-dimensional Arrays
How To Make an HTTP Server in Golang?
What is Slice Data Type in Go?
How do you set cookies in an HTTP request with an HTTP client in Go?