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 生日广州男生祝福语简短