Go Program to Check Character is Vowel or Consonant

Write a Go Program to check whether the given character is a vowel or consonant. Here, we used the If else statement to check the character is a, A, E, e, I, i, o, O, u, U. If True, Character is a Vowel; otherwise, it’s a consonant.

package main

import (
    "bufio"
    "fmt"
    "os"
)

func main() {

    reader := bufio.NewReader(os.Stdin)

    fmt.Print("Enter the Starting  Character = ")
    voch, _ := reader.ReadByte()

    if voch == 'a' || voch == 'e' || voch == 'i' || voch == 'o' || voch == 'u' ||
        voch == 'A' || voch == 'E' || voch == 'I' || voch == 'O' || voch == 'U' {
        fmt.Printf("%c is a VOWEL Character\n", voch)
    } else {
        fmt.Printf("%c is a CONSONANT\n", voch)
    }
}
Go Program to Check Character is Vowel or Consonant

Go Program to Check Character is Vowel or Consonant

In this Go example, the first if statement (if voch >= ‘A’ && voch <= ‘Z’) checks and converts the uppercase characters to lowercase. Next, we used only the lowercase Characters within the if condition to find the vowels and consonants.

package main

import (
    "bufio"
    "fmt"
    "os"
)

func main() {

    reader := bufio.NewReader(os.Stdin)

    fmt.Print("Enter the Starting  Character = ")
    voch, _ := reader.ReadByte()

    if voch >= 'A' && voch <= 'Z' {
        voch = voch + 32
    }

    if voch == 'a' || voch == 'e' || voch == 'i' || voch == 'o' || voch == 'u' {
        fmt.Printf("%c is a VOWEL Character\n", voch)
    } else {
        fmt.Printf("%c is a CONSONANT\n", voch)
    }
}
SureshMac:GoExamples suresh$ go run charVowCon2.go
Enter the Starting  Character = U
u is a VOWEL Character
SureshMac:GoExamples suresh$ go run charVowCon2.go
Enter the Starting  Character = o
o is a VOWEL Character
SureshMac:GoExamples suresh$ go run charVowCon2.go
Enter the Starting  Character = l
l is a CONSONANT

This Golang Program uses the ASCII codes to find whether the character is a vowel or consonant.

package main

import (
    "bufio"
    "fmt"
    "os"
)

func main() {

    reader := bufio.NewReader(os.Stdin)

    fmt.Print("Enter the Starting  Character = ")
    voch, _ := reader.ReadByte()

    if voch == 97 || voch == 101 || voch == 105 || voch == 111 || voch == 117 ||
        voch == 65 || voch == 69 || voch == 73 || voch == 79 || voch == 85 {
        fmt.Printf("%c is a VOWEL Character\n", voch)
    } else if (voch >= 97 && voch <= 122) || (voch >= 65 && voch <= 90) {
        fmt.Printf("%c is a CONSONANT\n", voch)
    } else {
        fmt.Println("Please enter a Valid Character")
    }
}
SureshMac:GoExamples suresh$ go run charVowCon3.go
Enter the Starting  Character = e
e is a VOWEL Character
SureshMac:GoExamples suresh$ go run charVowCon3.go
Enter the Starting  Character = O
O is a VOWEL Character
SureshMac:GoExamples suresh$ go run charVowCon3.go
Enter the Starting  Character = s
s is a CONSONANT