From 9d6ebe50f7afd59e15b41f1b5a40b03f362bb129 Mon Sep 17 00:00:00 2001 From: Kobigan Krishnananthan <84832594+Kobigan1223@users.noreply.github.com> Date: Thu, 21 Oct 2021 10:13:13 +0530 Subject: [PATCH] Algoritham Golang Added --- Golang Algorithm/ArmstrongNumber.go | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Golang Algorithm/ArmstrongNumber.go diff --git a/Golang Algorithm/ArmstrongNumber.go b/Golang Algorithm/ArmstrongNumber.go new file mode 100644 index 0000000..3e8a78e --- /dev/null +++ b/Golang Algorithm/ArmstrongNumber.go @@ -0,0 +1,32 @@ +//Program to check armstrong number + +package main + +import "fmt" + +func main() { + var number, tempNumber, remainder int //declaring variables for execution + var result int = 0 + + fmt.Print("Enter a number to be checked: ") + fmt.Scan(&number) + + tempNumber = number + + //executing the logic for checking an armstrong number + for { + remainder = tempNumber % 10 + result += remainder * remainder * remainder + tempNumber /= 10 + + if tempNumber == 0 { + break + } + } + + if result == number { + fmt.Printf("%d is an Armstrong number.", number) + } else { + fmt.Printf("%d is not an armstrong number.", number) + } +} \ No newline at end of file