Write a C program to delete the all vowels from a user-entered string. You
are required to delete the vowels from the string. Just not printing them is not a valid answer.
Sample Input1:Hello World (String Length=11)
Sample Output1: Hll Wrld (String Length=8)
Sample Input2: Apple (String Length=5)
Sample Output2:ppl (String Length=3)
CODE:
#include<stdio.h>
main()
{
// Variable declaration//
char a[25];
char b[25];
int i,j=0;
/*Input*/
printf("Enter string:");
gets(a);
/* actual Working */
for(i=0;a[i]!='\0';i++)//this loop will rununtil not equal to null
{
if(a[i]=='a' || a[i]=='e' || a[i]=='i' || a[i]=='o' || a[i]=='u')//if array index is equal to a or e or i or u or s then condition will run
{
a[i]='#';//here i replace array index value with #
}
}
printf("After remove vowels\n");
printf("Your string is:");
for(i=0;a[i]!='\0';i++)
{
if(a[i]>='a' && a[i]<='z' || a[i]>='A'&& a[i]<='Z' || a[i]==' ')//this will cheak that array index greater than a and less than z
{
printf("%c",a[i]);//this will print if condition is true
}
}
return 0;
}
Program Output:
For more problems click here
No comments:
Post a Comment