Vowel or consonant

Vowel or consonant - C Programming Example

This C Programing Example will take the desired alphabet as input. Output will show either the desired alphabet is a vowel or consonant.
C Programming Example
Vowel and Consonants

C Programming Code

    char p;
    printf(" Input the desired alphabet \n");
    if(p=='a'|| p=='A' || p=='e'|| p=='E'|| p=='i' || p=='I'|| p=='o'|| p=='O' || p=='u'|| p=='U')
        printf("The desired alphabet is a vowel \n");
            printf("The desired alphabet is a consonant \n");

Output of the code

C Programming Example
Vowel or Consonant


·     #include<stdio.h>
Ø This are called header file.A header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source filesThe C programming language provides many standard library functions for file input and output. These functions make up the bulk of the C standard library header<stdio.h>.In the other hand<conio.h> is a C header file used mostly by MS-DOS compilers to provide console input/output. It is not part of the C standard library or ISO C.This header declares several useful library functions for performing "console input and output" from a program.
·       main()
Ø In C, program execution starts from the main() function. The main function can in-turn call other functions. When main calls a function, it passes the execution control to that function. The function returns control to main when a return statement is executed or when end of function is reached.
·       char p ; The abbreviation char is used as a reserved keyword in a number of programming languages, such as C. It is short for character, which is a data type that holds one character (letter, number, etc.) of data.
·       printf() function
Ø C uses printf() function to write from the input devices. This function has been declared in the header file called stdio.h. Any text written within the pair of quotes ("") is displayed as such by printf() function on the screen. 
·       scanf() function
Ø This function is used to get input from the user of the program.scanf(“%c”,&p”)is used here. So, this program will read in a char value for “p”, variable that the user enters on the keyboard(%c is for the char).
·       printf("The desired alphabet is a vowel %c \n");
·       printf("The desired alphabet is a consonant %c \n");
Ø %c is used to print the main result.
·       getch() function
Ø getch() is used to hold the console(output) window on the screen after the whole program run is completed till the user enters a key from keyboard. This function is present in the header file called conio.h.

Final Result

This program will show you the desired alphabet is either a vowel or consonant. What you need to do is, just input the desired alphabet.

No comments

Powered by Blogger.