C 程序计算一个句子中重复的字母。
问题
编写一个程序来计算用户在控制台输入的字母。需要使用strlen()函数在屏幕上打印该字母在句子中重复的次数。
解决方案
我们用来计算字母的逻辑如下-
要求用户在运行时输入一个句子。
printf("Enter a sentence\n");
gets(str);要求用户在运行时输入一个字母。
printf("Enter a character to check how many times it is repeating\n");
scanf("%c",&c);计算句子中字母的逻辑如下-
for(i=0;i最后打印计数
例子
以下是计算在句子中重复次数的字母的C程序-
#include#include main(){ int i,count=0; char c,str[100]; printf("Enter a sentence\n"); gets(str); printf("Enter a character to check how many times it is repeating\n"); scanf("%c",&c); for(i=0;i 输出
执行上述程序时,它会产生以下输出-
Enter a sentence Here are the C Programming question and answers Enter a character to check how many times it is repeating n Letter n repeated 4 times
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短