In: Computer Science
IN C LANGUAGE
This program will read in a series of strings and print only the consonants (including Y) until the word "stop" appears. No string will be longer than 100 characters. A consonant is any letter that is not a vowel.
Don't forget to follow the standard read pattern!
Examples
Enter a string: Hello Hll Enter a string: World! Wrld Enter a string: 123! Enter a string: stop
Enter a string: stop
Source Code:
Output:
Code in text format (See above images of code for indentation):
/*include library files*/
#include <stdio.h>
/*main function*/
int main()
{
/*variables*/
char word[100];
int i=0;
while(1)
{
/*read a string from user*/
printf("Enter a string: ");
scanf("%s",word);
/*check for stop*/
if(strcmp(word,"stop")==0)
break;
/*using for loop print
consonants*/
for(i=0;word[i]!='\0';i++)
{
/*check for
alphabets*/
if(isalpha(word[i]))
{
/*check for not a vowels and print*/
if(word[i]!='a'&&word[i]!='e'&&word[i]!='i'&&word[i]!='o'&&word[i]!='u')
printf("%c",word[i]);
else
if(word[i]!='a'&&word[i]!='e'&&word[i]!='i'&&word[i]!='o'&&word[i]!='u')
printf("%c",word[i]);
}
}
/*newline*/
printf("\n\n");
}
return 0;
}