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 周末思念祝福语大全简短