주어진 문자열에서 모음을 삭제하기 위해 구현하는 데 사용하는 논리는 다음과 같습니다. -
for(i=0; i<len; i++) //repeat until i<len{
if(str[i]=='a' || str[i]=='e' || str[i]=='i' || //checking to delete the vowels
str[i]=='o' || str[i]=='u' || str[i]=='A' ||
str[i]=='E' || str[i]=='I' || str[i]=='O' ||
str[i]=='U'){
for(j=i; j<len; j++){
str[j]=str[j+1];
}
len--;
}
} 예시
다음은 주어진 문자열에서 모음을 삭제하는 C 프로그램입니다 -
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main(){
char str[20];
int len, i, j;
clrscr();
printf("Please Enter any String: ");
gets(str);
len=strlen(str);
for(i=0; i<len; i++){
if(str[i]=='a' || str[i]=='e' || str[i]=='i' || str[i]=='o' || str[i]=='u' || str[i]=='A' ||
str[i]=='E' || str[i]=='I' || str[i]=='O' || str[i]=='U'){
for(j=i; j<len; j++){
str[j]=str[j+1];
}
len--;
}
}
printf("After Deleting the vowels, the String is: %s",str);
getch();
} 출력
위의 프로그램이 실행되면 다음과 같은 결과가 생성됩니다 -
Please Enter any String: TutorialsPoint After Deleting the vowels, the String is: TtralsPint