本题要求编写程序,统计并输出某给定字符在给定字符串中出现的次数。
输入格式:
输入第一行给出一个以回车结束的字符串(少于80个字符);第二行输入一个字符。
输出格式:
在一行中输出给定字符在给定字符串中出现的次数。
输入样例:
programming is More fun!
m
输出样例:
2
题目集全集传送门
#include <stdio.h>
int main()
{
char ch[81];
char c,s;
int i,count=0;
gets(ch);
c=getchar();
for(i = 0; (s=ch[i])!='\0'; i++)
{
if(c==s)
count++;
}
printf("%d",count);
return 0;
}