从键盘输入一个字符串(不多于80个字符)统计其中字母a出现的次数,并删除字符串中所有的字母a

用c语言解答,用到字符数组的知识。

#include<stdio.h>
#define N 81
void main() { char s[N]; int a,i,j;
  gets(s); a=i=j=0;
  while ( s[i]!=0 ) {
    if ( s[i]=='a' ) a++;
    else { s[j]=s[i]; j++; }
    i++;
  }
  s[j]=0; printf("%s\n原始字符串中有%d个小写字母a。\n",s,a);
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-12-14
#include<stdio.h

int main() 

  char str[100],c; 
  int j,k,count=0; 
  printf("please input a string:"); 
  scanf("%s",str); 
  c='a'; 
  for(j=k=0;str[j]!='\0';j++) 
    if(str[j]!=c) 
      str[k++]=str[j]; 
    else 
      count++;
    str[k]='\0'; 
  printf("\n%s\n%d",str,count); 
}

本回答被网友采纳
相似回答