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
Find out how many logical processors used by current process
Golang program for drawing a Cuboid
Launches 10 Goroutines and each goroutine adding 10 values to a Channel
Creating Instances of Struct Types
Example of Interface with Type Embedding and Method Overriding in GO language
Go program to find TXT records of a domain
Send and Receive values from Channel
How do you handle HTTP client server compression in Go?
Golang program to demonstrates how to encode map data into a JSON string.
How To Make an HTTP Server in Golang?