早教吧 育儿知识 作业答案 考试题库 百科 知识分享

从键盘输入一个字符串,删除其中的字母a后输出.例如,输入字符串“abcaca”,输出bcc这是我编写的:#includemain(){intsr1[20],str2[20]={0};inti,j;scanf("%d",&str1);i=0;j=0;while(str1[i]!='\0'){while(str1[i!='a']){str2

题目详情
从键盘输入一个字符串,删除其中的字母a后输出.例如,输入字符串“abcaca”,输出bcc 这是我编写的:
#include
main(){
int sr1[20],str2[20]={0};
int i,j;
scanf("%d",&str1);
i=0;
j=0;
while (str1[i]!='\0'){
while(str1[i!='a']){
str2[j]=str1[i];
printf("%d",str2[j]);
j++;
}
i++;
}
str2[j]='\0';
}
有一个错误,请大神指导.
▼优质解答
答案和解析
/*
123abcoa90bcag
123bco90bcg
*/
#include
int main() {
char s[20];
int i = 0;
scanf("%s",s);
while(s[i]) {
if(s[i] != 'a')
printf("%c",s[i]);
i++;
}
printf("\n");
fflush(stdin);
getchar();
return 0;
}