2018/12/19统计字符出现字数

本题要求编写程序,统计并输出某给定字符在给定字符串中出现的次数。
输入格式:

输入第一行给出一个以回车结束的字符串(少于80个字符);第二行输入一个字符。
输出格式:

在一行中输出给定字符在给定字符串中出现的次数。
输入样例:

programming is More fun!
m
输出样例:

2

#include<stdio.h>
int main()
{
char str[80],a;
int k=0,i,count=0;
while((str[k]=getchar())!='\n')
k++;
scanf("%c",&a);
for(i=0;i<=k;i++){
if(str[i]==a)
count++;
}
printf("%d",count);
return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_44149969/article/details/85109227