Go language program to take a number between 0 to 9 and print the word representation for that number

Views: 122   

Following program shows you how to take a number between 0 to 9 and print the word representation for that number.
In this program we get numbers between 0 to 9 from user and print word representation using if condition

package main

import "fmt"

func main() {
  var input int
  fmt.Println("Enter a number between 0 to 9:")
  fmt.Scanf("%d", &input)
  if (input == 0) {
    fmt.Println("Zero")
  } else if (input == 1) {
    fmt.Println("One")
  } else if (input == 2) {
    fmt.Println("Two")
  } else if (input == 3) {
    fmt.Println("Three")
  } else if (input == 4) {
    fmt.Println("Four")
  } else if (input == 5) {
    fmt.Println("Five")
  } else if (input == 6) {
    fmt.Println("Six")
  } else if (input == 7) {
    fmt.Println("Seven")
  } else if (input == 8) {
    fmt.Println("Eight")
  } else if (input == 9) {
    fmt.Println("Nine")
  } else {
    fmt.Println("We don't have word representation for that number")
  }
}

Output:

Example1:

Enter a number between 0 to 9:
 4
Four

Example2:

Enter a number between 0 to 9:
 7
Seven

Example3:

Enter a number between 0 to 9:
 12
We don't have word representation for that number
On By