76 805
Assignments Done
Successfully Done
In June 2019

Answer to Question #23657 in C++ for Rohit Nagarkar

Question #23657
WAP to accept any character from user and print it's vowels and consonants in 'c' programming ???
Expert's answer
#include <conio.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>

char VOWELS[7] = "aoyeui";

int main()
char word[256] = {0};

/* Arrays used to store vowel and consonant letters
* found in the input word without repetitions */
char wordVowels[6] = {0};
char wordConsonants[20] = {0};

/* The numbers of different vowels and consonants found in this word */
int vowelCount = 0;
int consonantCount = 0;

register char letter;
register int isVowel;

/* Get a sequence of characters from user */
printf("Enter a word:\n");

for (int c = 0; word[c]; c++)
/* Check if current character is a letter */
letter = tolower(word[c]);
if (!isalpha(word[c]))
printf("Wrong character: %c\n", letter);

/* Check if it's a vowel */
isVowel = (int)strchr(VOWELS, letter);

/* Add it to array of vowels or to array of consonants */
if (isVowel && !strchr(wordVowels, letter))
wordVowels[vowelCount] = letter;

if (!isVowel && !strchr(wordConsonants, letter))
wordConsonants[consonantCount] = letter;

/* Output vowels found in the input word */
printf("Vowels met in this word:\n");
for (int v = 0; v < vowelCount; v++)
printf("& %c", wordVowels[v]);

/* Output consonants found in the input word */
printf("Consonants met in this word:\n");
for (int c = 0; c < consonantCount; c++)
printf("& %c", wordConsonants[c]);

return 0;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions