StudyLover
  • Home
  • Study Zone
  • Profiles
  • Typing Tutor
  • Contact us
  • Sign in
StudyLover Program #14 (U2): Character Classifier using switch
Download
  1. C Programming
  2. C Programming Practice
Program #13 (U2): Menu-driven Calculator using switch : Program #15 (U2): Sum of First N using three loops
C Programming Practice

Task: Read a single character and classify it as vowel, consonant, digit, or other. Use a switch with grouped cases for vowels.

 
/* 

  Program: Character Classifier using switch (U2)

  What it does:

    - Reads a single character.

    - Uses switch-grouped cases for vowels; checks for digits; else consonant/other.

*/

 
#include <stdio.h>

#include <ctype.h>

 
int main(void) {

    char ch;

 
    printf("Enter a character: ");

    if (scanf(" %c", &ch) != 1) {

        printf("Invalid input.

");

        return 0;

    }

 
    ch = tolower((unsigned char)ch);

 
    switch (ch) {

        case 'a': case 'e': case 'i': case 'o': case 'u':

            printf("vowel

"); break;

        default:

            if (ch >= '0' && ch <= '9') {

                printf("digit

");

            } else if (ch >= 'a' && ch <= 'z') {

                printf("consonant

");

            } else {

                printf("other

");

            }

    }

    return 0;

}

 

 

Program #13 (U2): Menu-driven Calculator using switch Program #15 (U2): Sum of First N using three loops
Our Products & Services
  • Home
Connect with us
  • Contact us
  • +91 82955 87844
  • Rk6yadav@gmail.com

StudyLover - About us

The Best knowledge for Best people.

Copyright © StudyLover
Powered by Odoo - Create a free website