Can you give C program that used string and array function that will accept strings as input and display the total number of vowels and consonants.
Sample Output:
Enter a string: Venus
No. of vowels: 2
No. of Consonants: 3
Can you give C program that will accept strings as input and display the total number of vowels and consonants
You'd need something along the lines of this:
char string[256];
int vowels=0, consonants=0;
cout %26lt;%26lt; "Input string: ";
cin.getline( string, 256, '\n');
cout %26lt;%26lt; "You typed: " %26lt;%26lt; string %26lt;%26lt; endl;
int i=0;
while (string[i] != '\0') {
if (string[i] == 'a' ||
string[i] == 'e' ||
string[i] == 'i' ||
string[i] == 'o' ||
string[i] == 'u' )
vowels++;
else
consonants++;
i++;
}//end of analyzing loop
cout %26lt;%26lt; "Number of vowels in your string: " %26lt;%26lt; vowels %26lt;%26lt; endl;
cout %26lt;%26lt; "Number of non-vowels in your string:" %26lt;%26lt; consonants %26lt;%26lt; endl;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment