60 430
Assignments Done
98,1%
Successfully Done
In April 2018

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");
gets(word);
putchar('\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);
continue;
}

/* 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;
vowelCount++;
}

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

/* 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]);
printf("\n\n");

/* 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]);

putchar('\n');
_getch();
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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions