QUESTION - 2
Write a C program to remove consonants from the string.
#include<stdio.h>
int main()
{
char a[20];
int i=0;
printf("Enter a lowercase String: ");
gets(a);
while(a[i]!='\0')
{
if(a[i]>95 && a[i]<122)
{
if(a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'|| a[i]=='u')
printf("%c",a[i]);
}
else
printf("%c",a[i]);
// to print spaces in between words of string
i++;
}
return 0;
}
Output:
Enter a lowercase String: hello world ↵
eo o
2 Comments
printf("%c",a[i]);
ReplyDelete}
else
printf("%c",a[i]);
How This statement is correct
check properly !! the first print statement is under nested if (where it is printing only vowels) and outside the nested if it is printing all spaces.
Delete