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 好听的元旦简短祝福语