Consonants in Range

The program must accept two lower case alphabets CH1 and CH2 as the input. The program must print all the consonants from CH1 to CH2 as the output.

Input Format:
The first line contains CH1 and CH2 separated by a space.
Output Format:
The first line contains all the consonants from CH1 to CH2.

Example Input/Output 1:
Input:
a z
Output:
b c d f g h j k l m n p q r s t v w x y z

Explanation:
All the consonants (except the vowels) from a to z are printed as the output.

Example Input/Output 2:
Input:

v h
Output:
v t s r q p n m l k j h

def is_consonant(c):
    return c not in 'aeiou'

def main():
    x, y = input().split()
    x, y = x[0], y[0]  # Ensure only the first character is taken if multiple are given

    while x != y:
        if is_consonant(x):
            print(x, end=" ")
        x = chr(ord(x) + 1) if x < y else chr(ord(x) - 1)

    if is_consonant(x):
        print(x)

if __name__ == "__main__":
    main()
import java.util.Scanner;

public class Consonants {

    public static boolean isConsonant(char c) {
        return "aeiou".indexOf(c) == -1;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        char x = scanner.next().charAt(0);
        char y = scanner.next().charAt(0);

        while (x != y) {
            if (isConsonant(x)) {
                System.out.print(x + " ");
            }
            x = (x < y) ? (char)(x + 1) : (char)(x - 1);
        }
        if (isConsonant(x)) {
            System.out.print(x);
        }
    }
}
#include <stdio.h>
#include <stdbool.h>

bool isConsonant(char c) {
    return !(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
}

int main() {
    char x, y;
    scanf(" %c %c", &x, &y);  // Added space before %c to ignore whitespace

    while (x != y) {
        if (isConsonant(x)) {
            printf("%c ", x);
        }
        x = (x < y) ? x + 1 : x - 1;
    }
    if (isConsonant(x)) {
        printf("%c", x);
    }

    return 0;
}
#include <iostream>

bool isConsonant(char c) {
    return !(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
}

int main() {
    char x, y;
    std::cin >> x >> y;

    while (x != y) {
        if (isConsonant(x)) {
            std::cout << x << " ";
        }
        x = (x < y) ? x + 1 : x - 1;
    }
    if (isConsonant(x)) {
        std::cout << x;
    }

    return 0;
}
Previous Article

Alphabets Positions Reversed

Next Article

Swap - Multiples of X and Y

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *