GO Program to check character is vowel or consonant

How to check character is vowel or consonant

Here we are explaining how to check character is vowel or consonant in the Go program. We can use the built-in function fmt.println() to print anything and fmt.scanln() for reading the values. This function is defined under the fmt package and it helps to write standard output. In order to use these functions, we need to import the “fmt” package.

func (r *Reader) ReadByte() (byte, error) 

ReadByte implements the io.ByteReader interface

 

How to check character is vowel or consonant in GO Program

We are using fmt.println() function for printing the string to the output screen. Here we are showing how to check character is vowel or consonant in the Go language. Here variable chr is used to hold the read character. For reading the character create the reader using NewReader. Check the character read is a vowel or consonant by comparing the characters with vowels. Finally print the results. Given below are the steps which are used in the Go program. 

ALGORITHM

STEP 1: Import the package fmt, bufio, os

STEP 2: Start function main()

STEP 3: Create a reader using NewReader as reader := bufio.NewReader(os.Stdin)

STEP 4: Read the character into variable chr as chr, _, _ := reader.ReadRune()

STEP 5: Check the character is vowel or consonant by comparing the characters with vowels

STEP 6: Use if statement for printing proper message

 

GO Source Code

                                          package main

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

func main() {

    reader := bufio.NewReader(os.Stdin)

    fmt.Print("Enter the character = ")
    chr, _ := reader.ReadByte()

    if chr == 'a' || chr == 'e' || chr == 'i' || chr == 'o' || chr == 'u' ||
        chr == 'A' || chr == 'E' || chr == 'I' || chr == 'O' || chr == 'U' {
        fmt.Printf("%c is a VOWEL character\n", chr)
    } else {
        fmt.Printf("%c is a CONSONANT\n", chr)
    }
}
                                      

OUTPUT

Enter the character = e
e is a VOWEL character

Enter the character = c
c is a CONSONANT