{"id":740,"date":"2026-10-05T09:00:00","date_gmt":"2026-10-05T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/?p=740"},"modified":"2026-11-29T01:29:41","modified_gmt":"2026-11-28T19:59:41","slug":"go-number-programs","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-number-programs\/","title":{"rendered":"Go Number Programs: Prime, Palindrome, Armstrong and More"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go number programs check special properties of numbers, such as whether a number is prime, a palindrome or an Armstrong number. These are some of the most asked questions in coding rounds for freshers and experienced developers alike. In this post, you will write thirteen number programs with their exact output, and then practice the tricky edge cases interviewers like to test.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You will use everything from our <a href=\"https:\/\/smitabharat.com\/blog\/go-loop-programs\/\">Go loop programs<\/a> and <a href=\"https:\/\/smitabharat.com\/blog\/go-if-else-programs\/\">Go if else programs<\/a>, so finish those first. We also split each check into a small function, which our <a href=\"https:\/\/smitabharat.com\/blog\/go-functions-beginners-guide\/\">Go functions guide<\/a> explains. All programs were tested on Go 1.27.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are Go Number Programs?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Go number programs take a whole number and test a rule about its digits or divisors. For example, a prime number has exactly two divisors, and a palindrome number reads the same both ways.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of these programs as detectives. Each one asks a different question about a number, collects clues with <code>%<\/code> and <code>\/<\/code>, and gives a yes or no answer. Once you learn the clue tools, you can solve almost any number puzzle.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Go Number Programs Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Go number programs look like school maths, but they teach real skills. You learn to break a number into digits, to loop only as far as needed, and to handle edge cases such as 0, 1 and negative numbers.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Coding rounds:<\/strong> prime, palindrome and Armstrong checks appear in almost every fresher test.<\/li>\n\n\n<li><strong>Problem solving:<\/strong> they train you to think about loops, limits and speed.<\/li>\n\n\n<li><strong>Real use:<\/strong> GCD helps simplify fractions, and base conversion is used in networking and file formats.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How Go Number Programs Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Most Go number programs use two simple tools. <code>n % 10<\/code> gives the last digit, and <code>n \/ 10<\/code> removes it. Repeat these in a loop, and you can visit every digit from right to left.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-number-programs-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-number-programs-diagram-1-1024x640.png\" alt=\"Go number programs diagram showing digit extraction with modulo and division\" class=\"wp-image-723\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-number-programs-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-number-programs-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-number-programs-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-number-programs-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-number-programs-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Each pass takes the last digit with n % 10, uses it, and removes it with n \/ 10 until the number becomes 0.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The table below lists the number types in this post with an example of each.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Number type<\/th><th>Rule<\/th><th>Example<\/th><\/tr><\/thead><tbody><tr><td>Prime<\/td><td>Only divisible by 1 and itself<\/td><td>29<\/td><\/tr><tr><td>Palindrome<\/td><td>Same digits forwards and backwards<\/td><td>1221<\/td><\/tr><tr><td>Armstrong<\/td><td>Sum of digits raised to digit count equals the number<\/td><td>153<\/td><\/tr><tr><td>Perfect<\/td><td>Sum of proper divisors equals the number<\/td><td>28<\/td><\/tr><tr><td>Strong<\/td><td>Sum of digit factorials equals the number<\/td><td>145<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Prime Go Number Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Prime numbers are the most popular number questions, so we start with them.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 1: Check if a Number is Prime<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We only need to test divisors up to the square root of the number. If a number had a larger factor, it would also have a smaller one.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ isPrime returns true when number has no divisors other than 1 and itself\nfunc isPrime(number int) bool {\n    \/\/ Step 1: 0, 1 and negative numbers are not prime\n    if number &lt; 2 {\n        return false\n    }\n    \/\/ Step 2: try every divisor up to the square root\n    \/\/ i*i &lt;= number is the same as i &lt;= square root of number\n    for i := 2; i*i &lt;= number; i++ {\n        if number%i == 0 {\n            return false \/\/ found a divisor, so it is not prime\n        }\n    }\n    \/\/ Step 3: no divisor found\n    return true\n}\n\nfunc main() {\n    numbers := []int{1, 2, 17, 21, 97}\n    for _, number := range numbers {\n        fmt.Println(number, \"prime:\", isPrime(number))\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1 prime: false\n2 prime: true\n17 prime: true\n21 prime: false\n97 prime: true<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The function first throws out numbers below 2. Then it tries each divisor from 2 upward and stops at the first one it finds. <code>i*i &lt;= number<\/code> is the square root check without using floats. Also, 1 is not prime, because it has only one divisor.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 2: All Primes up to 50 with a Sieve<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The Sieve of Eratosthenes finds all primes in a range quickly. It crosses out the multiples of each prime.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    limit := 50\n\n    \/\/ make creates a slice of 51 bools, all false at the start.\n    \/\/ composite[x] becomes true when x is NOT prime.\n    composite := make([]bool, limit+1)\n\n    \/\/ Step 1: cross out the multiples of each prime\n    for i := 2; i*i &lt;= limit; i++ {\n        if !composite[i] { \/\/ ! means \"not\", so this reads \"if i is still prime\"\n            for j := i * i; j &lt;= limit; j += i {\n                composite[j] = true\n            }\n        }\n    }\n\n    \/\/ Step 2: print every number that was never crossed out\n    for number := 2; number &lt;= limit; number++ {\n        if !composite[number] {\n            fmt.Print(number, \" \")\n        }\n    }\n    fmt.Println()\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>2 3 5 7 11 13 17 19 23 29 31 37 41 43 47<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For 2, the program crosses out 4, 6, 8 and so on. Then it does the same for 3, 5 and 7. <code>composite[j] = true<\/code> marks a number that has a smaller factor. Every number left unmarked is prime.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Digit-Based Go Number Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These Go number programs break a number into its digits.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 3: Print the Digits of a Number<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This easy first version shows the two digit tools from the diagram above. It prints each digit from right to left.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    n := 4719 \/\/ n is the number, same name as in the diagram\n\n    for n &gt; 0 {\n        digit := n % 10 \/\/ Step 1: % 10 gives the last digit\n        n = n \/ 10      \/\/ Step 2: \/ 10 removes the last digit\n        fmt.Println(\"Digit:\", digit, \"| left:\", n)\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Digit: 9 | left: 471\nDigit: 1 | left: 47\nDigit: 7 | left: 4\nDigit: 4 | left: 0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On each pass, <code>n % 10<\/code> picks the last digit and <code>n \/ 10<\/code> drops it. So 4719 becomes 471, then 47, then 4 and finally 0. When <code>n<\/code> reaches 0, the loop stops. Every digit program below is built on this loop.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 4: Palindrome Number<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We reverse the number and compare it with the original.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ isPalindrome returns true when number reads the same both ways\nfunc isPalindrome(number int) bool {\n    if number &lt; 0 {\n        return false\n    }\n    original := number \/\/ keep a copy to compare at the end\n    reversed := 0\n\n    for number &gt; 0 {\n        lastDigit := number % 10\n        reversed = reversed*10 + lastDigit \/\/ add the digit to the end of reversed\n        number = number \/ 10\n    }\n    return original == reversed\n}\n\nfunc main() {\n    numbers := []int{121, 1221, 123, 7, -121}\n    for _, number := range numbers {\n        fmt.Println(number, \"palindrome:\", isPalindrome(number))\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>121 palindrome: true\n1221 palindrome: true\n123 palindrome: false\n7 palindrome: true\n-121 palindrome: false<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The loop builds the reversed number one digit at a time. For 123, <code>reversed<\/code> grows from 3 to 32 to 321. Then the function compares it with the saved copy. Negative numbers are not palindromes, because &#8220;-121&#8221; reversed is &#8220;121-&#8220;.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 5: Armstrong Number<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">An Armstrong number equals the sum of its digits, each raised to the number of digits. For 153, that is 1 + 125 + 27.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ power multiplies base by itself exponent times, using only ints\nfunc power(base int, exponent int) int {\n    result := 1\n    for range exponent { \/\/ repeat exponent times\n        result *= base\n    }\n    return result\n}\n\n\/\/ isArmstrong checks if number equals the sum of its digits raised to the digit count\nfunc isArmstrong(number int) bool {\n    digitCount := len(fmt.Sprint(number)) \/\/ Sprint turns 153 into the text \"153\"\n    sum := 0\n    remaining := number \/\/ work on a copy so number stays the same\n\n    for remaining &gt; 0 {\n        lastDigit := remaining % 10\n        sum += power(lastDigit, digitCount)\n        remaining = remaining \/ 10\n    }\n    return sum == number\n}\n\nfunc main() {\n    for number := 1; number &lt;= 1000; number++ {\n        if isArmstrong(number) {\n            fmt.Print(number, \" \")\n        }\n    }\n    fmt.Println()\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1 2 3 4 5 6 7 8 9 153 370 371 407<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For each number, the program counts its digits and then raises each digit to that count. We count digits with <code>len(fmt.Sprint(number))<\/code>, which turns the number into text. Our own <code>power<\/code> function keeps the maths in ints, so there are no float rounding errors.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 6: Strong Number<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A strong number equals the sum of the factorials of its digits. For 145, that is 1! + 4! + 5! = 1 + 24 + 120.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    \/\/ Step 1: store the factorials of 0 to 9 in an array of 10 ints.\n    \/\/ {1} sets factorials[0] to 1; the rest start at 0.\n    factorials := [10]int{1}\n    for i := 1; i &lt; 10; i++ {\n        factorials[i] = factorials[i-1] * i\n    }\n\n    \/\/ Step 2: test each number\n    numbers := []int{145, 40585, 123}\n    for _, number := range numbers {\n        sum := 0\n        remaining := number\n        for remaining &gt; 0 {\n            lastDigit := remaining % 10\n            sum += factorials[lastDigit] \/\/ look up the factorial of this digit\n            remaining = remaining \/ 10\n        }\n        fmt.Println(number, \"strong:\", sum == number)\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>145 strong: true\n40585 strong: true\n123 strong: false<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We work out the factorials of 0 to 9 once and store them in an array. Then each digit just looks up its value, which is faster. For 145, the sum is 1 + 24 + 120, which matches the number.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 7: Neon Number<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A neon number equals the sum of the digits of its square. For example, 9 squared is 81, and 8 + 1 = 9.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ digitSum adds up all the digits of a number\nfunc digitSum(number int) int {\n    sum := 0\n    for number &gt; 0 {\n        sum += number % 10\n        number = number \/ 10\n    }\n    return sum\n}\n\nfunc main() {\n    numbers := []int{1, 9, 12, 45}\n    for _, number := range numbers {\n        square := number * number\n        isNeon := digitSum(square) == number \/\/ true or false\n        fmt.Println(number, \"square:\", square, \"neon:\", isNeon)\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1 square: 1 neon: true\n9 square: 81 neon: true\n12 square: 144 neon: false\n45 square: 2025 neon: false<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">First, the program squares each number. Next, <code>digitSum<\/code> adds up the digits of that square. If the sum equals the original number, it is a neon number. For 12, the digits of 144 add up to 9, so the answer is false.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 8: Count, Sum and Product of Digits<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This program finds three facts about the digits in one loop.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    number := 50721\n    count := 0\n    sum := 0\n    product := 1 \/\/ start at 1, because anything times 0 is 0\n\n    remaining := number\n    for remaining &gt; 0 {\n        digit := remaining % 10\n        count++\n        sum += digit\n        product *= digit\n        remaining = remaining \/ 10\n    }\n    fmt.Println(\"Digits:\", count, \"Sum:\", sum, \"Product:\", product)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Digits: 5 Sum: 15 Product: 0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each pass takes one digit and updates all three totals. The sum is 5 + 0 + 7 + 2 + 1 = 15. The product is 0, because one digit is 0. Interviewers often add a 0 to see if you notice.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Divisor-Based Go Number Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These Go number programs look at the numbers that divide n.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 9: Factors of a Number<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A factor is a number that divides another number with no remainder.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    number := 36\n    fmt.Print(\"Factors of \", number, \": \")\n\n    \/\/ Try every number from 1 up to number itself\n    for i := 1; i &lt;= number; i++ {\n        if number%i == 0 { \/\/ no remainder, so i is a factor\n            fmt.Print(i, \" \")\n        }\n    }\n    fmt.Println()\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Factors of 36: 1 2 3 4 6 9 12 18 36<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The loop tries each value from 1 to 36. When the remainder is 0, that value is a factor, so the program prints it. This simple version is easy to read, but it is slow for big numbers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 10: Perfect Number<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A perfect number equals the sum of its proper divisors, which are all divisors except itself.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ isPerfect returns true when number equals the sum of its proper divisors\nfunc isPerfect(number int) bool {\n    if number &lt; 2 {\n        return false\n    }\n    sum := 1 \/\/ 1 divides every number\n\n    for i := 2; i*i &lt;= number; i++ {\n        if number%i == 0 {\n            partner := number \/ i \/\/ divisors come in pairs, like 2 and 14 for 28\n            sum += i\n            if i != partner { \/\/ do not add the same divisor twice (e.g. 6 x 6)\n                sum += partner\n            }\n        }\n    }\n    return sum == number\n}\n\nfunc main() {\n    for number := 1; number &lt;= 10000; number++ {\n        if isPerfect(number) {\n            fmt.Print(number, \" \")\n        }\n    }\n    fmt.Println()\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>6 28 496 8128<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each divisor <code>i<\/code> comes with a partner <code>number \/ i<\/code>. So we add both and only loop to the square root, which makes the program fast. For 28, the sum is 1 + 2 + 14 + 4 + 7, which is 28.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 11: GCD and LCM<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The GCD is the largest number that divides both. Euclid&#8217;s method finds it by repeated remainders.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ gcd finds the greatest common divisor with Euclid's method\nfunc gcd(first int, second int) int {\n    for second != 0 {\n        remainder := first % second\n        first = second     \/\/ the old second becomes the new first\n        second = remainder \/\/ the remainder becomes the new second\n    }\n    return first\n}\n\nfunc main() {\n    first := 48\n    second := 180\n\n    common := gcd(first, second)\n    lcm := first \/ common * second \/\/ divide first to keep the numbers small\n\n    fmt.Println(\"GCD:\", common)\n    fmt.Println(\"LCM:\", lcm)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>GCD: 12\nLCM: 720<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Euclid&#8217;s loop keeps replacing the pair with the smaller number and the remainder. When the remainder is 0, the other number is the GCD. We write <code>first \/ common * second<\/code> instead of <code>first * second \/ common<\/code>. Dividing first keeps the numbers small and avoids overflow.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Base Conversion Go Number Programs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Computers store numbers in binary. These Go number programs move between bases.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 12: Decimal to Binary, Octal and Hex<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This program shows the manual way first, then the ready-made ways.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strconv\" \/\/ strconv converts between numbers and text\n)\n\n\/\/ toBinary builds the binary text of a number by dividing by 2\nfunc toBinary(number int) string {\n    if number == 0 {\n        return \"0\"\n    }\n    bits := \"\"\n    for number &gt; 0 {\n        remainder := number % 2               \/\/ 0 or 1\n        bits = strconv.Itoa(remainder) + bits \/\/ Itoa turns 1 into \"1\"; put it in front\n        number = number \/ 2\n    }\n    return bits\n}\n\nfunc main() {\n    number := 45\n    fmt.Println(\"Manual binary:\", toBinary(number))\n    fmt.Println(\"strconv binary:\", strconv.FormatInt(int64(number), 2)) \/\/ base 2\n    \/\/ %b is binary, %o is octal, %x is hex\n    fmt.Printf(\"Printf: %b %o %x\\n\", number, number, number)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Manual binary: 101101\nstrconv binary: 101101\nPrintf: 101101 55 2d<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The manual way divides by 2 and keeps the remainders. Each new remainder goes in front, so the bits end up in the right order. In real code, <code>strconv.FormatInt<\/code> or <code>%b<\/code> does it for you.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program 13: Binary to Decimal<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>strconv.ParseInt<\/code> reads text in any base and gives back a number.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strconv\"\n)\n\nfunc main() {\n    \/\/ ParseInt(text, base, bit size) returns the number and an error value.\n    \/\/ err is the error value; nil means \"no error\".\n    number, err := strconv.ParseInt(\"101101\", 2, 64)\n    fmt.Println(number, err)\n\n    \/\/ _ ignores the error, because we know \"ff\" is valid hex\n    hexNumber, _ := strconv.ParseInt(\"ff\", 16, 64)\n    fmt.Println(hexNumber)\n\n    \/\/ \"2\" is not a binary digit, so this returns an error\n    _, err = strconv.ParseInt(\"1021\", 2, 64)\n    fmt.Println(err)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>45 &lt;nil&gt;\n255\nstrconv.ParseInt: parsing \"1021\": invalid syntax<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The second argument is the base, so 2 means binary and 16 means hex. When the text is valid, <code>err<\/code> is <code>nil<\/code>. A &#8220;2&#8221; is not a valid binary digit, so the last call returns an error.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Number Programs: Loop to n vs Square Root<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Speed matters in Go number programs, because inputs can be large. The diagram and table below compare a full loop with a square root loop.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-number-programs-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-number-programs-diagram-2-1024x640.png\" alt=\"Go number programs comparison of a full loop and a square root loop for prime checks\" class=\"wp-image-724\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-number-programs-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-number-programs-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-number-programs-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-number-programs-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-number-programs-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Checking divisors only up to the square root gives the same answer with far fewer steps.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Loop to n<\/th><th>Loop to square root<\/th><\/tr><\/thead><tbody><tr><td>Steps for n = 1,000,000<\/td><td>About 1,000,000<\/td><td>About 1,000<\/td><\/tr><tr><td>Correct for prime check<\/td><td>Yes<\/td><td>Yes<\/td><\/tr><tr><td>Condition<\/td><td>i &lt; n<\/td><td>i*i &lt;= n<\/td><\/tr><tr><td>Finds all divisors<\/td><td>Yes, directly<\/td><td>Yes, with pairs i and n\/i<\/td><\/tr><tr><td>Good for big inputs<\/td><td>No<\/td><td>Yes<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So always loop to the square root for prime and divisor problems. It is the first thing interviewers look for.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes in Go Number Programs<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Calling 1 prime:<\/strong> 1 has only one divisor, so it is not prime.<\/li>\n\n\n<li><strong>Changing the original number:<\/strong> copy the number into <code>remaining<\/code> before the digit loop, or you cannot compare at the end.<\/li>\n\n\n<li><strong>Overflow when reversing:<\/strong> reversing a large <code>int32<\/code> can overflow, so use <code>int<\/code> or check limits.<\/li>\n\n\n<li><strong>Using math.Pow for digits:<\/strong> it returns <code>float64<\/code>, which can cause rounding surprises. Write a small int power function.<\/li>\n\n\n<li><strong>Forgetting zero:<\/strong> a loop with <code>for number &gt; 0<\/code> never runs for 0, so handle it on its own.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Go Number Programs<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Put each check in its own function<\/strong>, such as <code>isPrime(number int) bool<\/code>, so it is easy to test.<\/li>\n\n\n<li><strong>Loop to the square root<\/strong> for any divisor problem.<\/li>\n\n\n<li><strong>Handle edge cases first<\/strong>: negative numbers, 0 and 1.<\/li>\n\n\n<li><strong>Use strconv for bases<\/strong> in real code, and the manual way only to show you understand it.<\/li>\n\n\n<li><strong>Test with known answers<\/strong>, such as 153 for Armstrong and 28 for perfect.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Go Number Programs Interview Questions and Answers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Interviewers ask these Go number programs often in coding rounds. Each program is complete, with real output from Go 1.27.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Prime and Divisor Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1. Why do we loop only to the square root in a prime check?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If n = a x b and both a and b were bigger than the square root, their product would be bigger than n. So at least one factor is small, and we find it before the square root.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    count := 0\n    for number := 2; number &lt; 100; number++ {\n        isPrime := true \/\/ assume prime until we find a divisor\n        for i := 2; i*i &lt;= number; i++ {\n            if number%i == 0 {\n                isPrime = false\n                break \/\/ stop the inner loop early\n            }\n        }\n        if isPrime {\n            count++\n        }\n    }\n    fmt.Println(count)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>25<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">There are 25 primes below 100. The <code>break<\/code> stops the inner loop as soon as a divisor is found, which saves time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3. Is 2 the only even prime?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Every other even number divides by 2, so it has at least three divisors. That is why many prime checks handle 2 first and then test only odd numbers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ gcd finds the greatest common divisor with Euclid's method\nfunc gcd(first int, second int) int {\n    for second != 0 {\n        remainder := first % second\n        first = second\n        second = remainder\n    }\n    return first\n}\n\nfunc main() {\n    fmt.Println(gcd(17, 5), gcd(0, 9), gcd(21, 14))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1 9 7<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">17 and 5 share no factor, so the GCD is 1. The GCD of 0 and any number is that number.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Digit Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    number := 1200\n    reversed := 0\n    for number &gt; 0 {\n        reversed = reversed*10 + number%10\n        number = number \/ 10\n    }\n    fmt.Println(reversed)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>21<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The trailing zeros become leading zeros, which a number does not keep. So 1200 reversed is 21, and 1200 is not a palindrome.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6. How do you check a palindrome number using strings?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strconv\"\n)\n\nfunc main() {\n    text := strconv.Itoa(12321) \/\/ Itoa turns the number into the text \"12321\"\n    isPalindrome := true\n\n    \/\/ i starts at the front, j starts at the back, and they move toward each other\n    for i, j := 0, len(text)-1; i &lt; j; i, j = i+1, j-1 {\n        if text[i] != text[j] { \/\/ text[i] is the character at position i\n            isPalindrome = false\n            break\n        }\n    }\n    fmt.Println(isPalindrome)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>true<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Convert the number to text, then compare the first and last characters while moving inward. It is easy to read, but the maths version uses less memory.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    number := 9875\n    \/\/ Keep adding the digits until only one digit is left\n    for number &gt; 9 {\n        sum := 0\n        for number &gt; 0 {\n            sum += number % 10\n            number = number \/ 10\n        }\n        number = sum\n    }\n    fmt.Println(number)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This finds the digital root. 9+8+7+5 is 29, then 2+9 is 11, then 1+1 is 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8. Is 9474 an Armstrong number?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. It has 4 digits, and 9^4 + 4^4 + 7^4 + 4^4 = 6561 + 256 + 2401 + 256 = 9474. Armstrong numbers can have any number of digits.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    number := 0\n    digits := 0\n    for number &gt; 0 {\n        digits++\n        number = number \/ 10\n    }\n    fmt.Println(digits)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The loop never runs for 0, so it reports 0 digits. But 0 has one digit, so real code must handle this case separately.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Conversion and Output Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"strconv\"\n)\n\nfunc main() {\n    \/\/ FormatInt(number, base) writes a number in the given base\n    fmt.Println(strconv.Itoa(255), strconv.FormatInt(255, 16), strconv.FormatInt(-5, 2))\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>255 ff -101<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>FormatInt<\/code> works with any base from 2 to 36. For negative numbers, it simply adds a minus sign.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    \/\/ 0b = binary, 0o = octal, 0x = hex; _ is only for easy reading\n    fmt.Println(0b1010, 0o17, 0x1F, 1_000_000)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>10 15 31 1000000<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Go lets you write numbers in binary with <code>0b<\/code>, octal with <code>0o<\/code> and hex with <code>0x<\/code>. Underscores make big numbers easier to read and do not change the value.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12. How do you check if a number is a power of two?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ isPowerOfTwo uses a bit trick: a power of two has exactly one 1 bit.\n\/\/ number-1 flips that bit off and turns the lower bits on (8 = 1000, 7 = 0111),\n\/\/ so number &amp; (number-1) is 0 only for powers of two.\nfunc isPowerOfTwo(number int) bool {\n    return number &gt; 0 &amp;&amp; number&amp;(number-1) == 0\n}\n\nfunc main() {\n    numbers := []int{1, 8, 12, 64}\n    for _, number := range numbers {\n        fmt.Println(number, isPowerOfTwo(number))\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1 true\n8 true\n12 false\n64 true<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A power of two has exactly one bit set. <code>number &amp; (number-1)<\/code> clears that bit, so the result is 0 only for powers of two. For 12, which is 1100 in binary, a bit is left over, so the answer is false.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    sum := 0\n    for i := 1; i &lt; 1000; i++ {\n        if i%3 == 0 || i%5 == 0 { \/\/ || means \"or\"\n            sum += i\n        }\n    }\n    fmt.Println(sum)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>233168<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is a classic puzzle: the sum of all multiples of 3 or 5 below 1000. The <code>||<\/code> makes sure numbers like 15 are counted once.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14. How do you find large factorials in Go?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use the <code>math\/big<\/code> package. A normal <code>uint64<\/code> overflows after 20!, but <code>big.Int<\/code> grows as needed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"math\/big\" \/\/ big numbers with no size limit\n)\n\nfunc main() {\n    \/\/ new(big.Int) makes an empty big number and returns a pointer to it.\n    \/\/ MulRange(1, 25) multiplies 1 x 2 x ... x 25 and stores the answer.\n    factorial := new(big.Int).MulRange(1, 25)\n    fmt.Println(factorial)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>15511210043330985984000000<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>MulRange(1, 25)<\/code> multiplies every number from 1 to 25, which is 25!.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15. What is a neon number?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A neon number is one where the sum of the digits of its square equals the number. For example, 9 squared is 81, and 8 + 1 = 9. Program 7 above checks it with the same digit loop as the other programs here.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This task combines two Go number programs from above. Write a program that prints all twin primes below 100. Twin primes are pairs of primes that differ by 2, such as (11, 13). Hint: reuse the <code>isPrime<\/code> function from Program 1.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pkg.go.dev\/strconv\">strconv package documentation<\/a><\/li>\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/math\/big\">math\/big package documentation<\/a><\/li>\n\n\n<li><a href=\"https:\/\/go.dev\/ref\/spec#Integer_literals\">Go spec: integer literals<\/a><\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go number programs use <code>n % 10<\/code> to get a digit and <code>n \/ 10<\/code> to remove it.<\/li>\n\n\n<li>Loop to the square root for prime and divisor checks.<\/li>\n\n\n<li>Handle 0, 1 and negative numbers before the main logic.<\/li>\n\n\n<li>Use <code>strconv.FormatInt<\/code> and <code>ParseInt<\/code> to convert between bases.<\/li>\n\n\n<li>Use <code>math\/big<\/code> when results are too large for <code>uint64<\/code>.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Next, we use nested loops to draw shapes. Read <a href=\"https:\/\/smitabharat.com\/blog\/go-pattern-programs\/\">Go pattern programs with stars, numbers and pyramids<\/a>. To revise loops before that, read <a href=\"https:\/\/smitabharat.com\/blog\/go-loop-programs\/\">Go loop programs with output<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go number programs check special properties of numbers, such as whether a number is prime, a palindrome or an Armstrong number. These are some&hellip;<\/p>\n","protected":false},"author":1,"featured_media":725,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[106],"tags":[96,95,11,110,104],"swapz_series":[],"class_list":["post-740","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-programs","tag-beginner","tag-go-interview-questions","tag-go-lang","tag-go-number-programs","tag-go-programs"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Number Programs: Prime, Palindrome, Armstrong<\/title>\n<meta name=\"description\" content=\"Go number programs with output: prime, palindrome, Armstrong, perfect and strong numbers, GCD and binary, plus interview questions with answers.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-number-programs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Number Programs: Prime, Palindrome, Armstrong\" \/>\n<meta property=\"og:description\" content=\"Go number programs with output: prime, palindrome, Armstrong, perfect and strong numbers, GCD and binary, plus interview questions with answers.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-number-programs\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-05T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-28T19:59:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-number-programs-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"17 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-number-programs\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-number-programs\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Number Programs: Prime, Palindrome, Armstrong and More\",\"datePublished\":\"2026-10-05T03:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-number-programs\\\/\"},\"wordCount\":2033,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-number-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-number-programs-featured.png\",\"keywords\":[\"Beginner\",\"Go Interview Questions\",\"Go Lang\",\"Go Number Programs\",\"Go Programs\"],\"articleSection\":[\"Go Programs\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-number-programs\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-number-programs\\\/\",\"name\":\"Go Number Programs: Prime, Palindrome, Armstrong\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-number-programs\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-number-programs\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-number-programs-featured.png\",\"datePublished\":\"2026-10-05T03:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:41+00:00\",\"description\":\"Go number programs with output: prime, palindrome, Armstrong, perfect and strong numbers, GCD and binary, plus interview questions with answers.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-number-programs\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-number-programs\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-number-programs\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-number-programs-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-number-programs-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Number Programs featured image: output of prime, palindrome and Armstrong checks\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-number-programs\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Number Programs: Prime, Palindrome, Armstrong and More\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go Number Programs: Prime, Palindrome, Armstrong","description":"Go number programs with output: prime, palindrome, Armstrong, perfect and strong numbers, GCD and binary, plus interview questions with answers.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-number-programs\/","og_locale":"en_US","og_type":"article","og_title":"Go Number Programs: Prime, Palindrome, Armstrong","og_description":"Go number programs with output: prime, palindrome, Armstrong, perfect and strong numbers, GCD and binary, plus interview questions with answers.","og_url":"https:\/\/smitabharat.com\/blog\/go-number-programs\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-10-05T03:30:00+00:00","article_modified_time":"2026-11-28T19:59:41+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-number-programs-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"17 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-number-programs\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-number-programs\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Number Programs: Prime, Palindrome, Armstrong and More","datePublished":"2026-10-05T03:30:00+00:00","dateModified":"2026-11-28T19:59:41+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-number-programs\/"},"wordCount":2033,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-number-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-number-programs-featured.png","keywords":["Beginner","Go Interview Questions","Go Lang","Go Number Programs","Go Programs"],"articleSection":["Go Programs"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-number-programs\/","url":"https:\/\/smitabharat.com\/blog\/go-number-programs\/","name":"Go Number Programs: Prime, Palindrome, Armstrong","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-number-programs\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-number-programs\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-number-programs-featured.png","datePublished":"2026-10-05T03:30:00+00:00","dateModified":"2026-11-28T19:59:41+00:00","description":"Go number programs with output: prime, palindrome, Armstrong, perfect and strong numbers, GCD and binary, plus interview questions with answers.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-number-programs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-number-programs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-number-programs\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-number-programs-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-number-programs-featured.png","width":2400,"height":1260,"caption":"Go Number Programs featured image: output of prime, palindrome and Armstrong checks"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-number-programs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Number Programs: Prime, Palindrome, Armstrong and More"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/740","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=740"}],"version-history":[{"count":2,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/740\/revisions"}],"predecessor-version":[{"id":874,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/740\/revisions\/874"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/725"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=740"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=740"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=740"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}