解释:
#include
int count(char s[],char letter)
{ int i=0,sum=0;
while(s[i]!='\0')
{ if(s[i]==letter)
sum++;
i++;
}
return sum;
}
main()
{ char s[100], letter;
int i, sum;
printf("请输入一个字符串:\n");
gets(s);
printf("请输入一个字符:\n");
scanf("%c",&letter);
sum=count(s,letter);
printf("%c字符在字符串出现的次数是%d\n",letter,sum);
}
#include
using namespace std;
int count(char s[],char letter)
{
int i=0,sum=0;
while(s[i]!='\0')
{
if(s[i]==letter)
sum++;
i++;
}
return sum;
}
int main()
{
char s[100],c;
cout<<"输入字符串"<
cout<<"输入字符"<
cout<
}