#include <stdio.h>
#include <string.h>

void tongji(char *ss, int *pp);

void main()
{
    char tt[100];
    int pp[26] = {0}; // 初始化为0
    printf("请输入一个字符串:");
    gets(tt); // 输入字符串
    tongji(tt, pp); // 调用函数统计字母出现次数
    // 输出结果
    for(int i = 0; i < 26; i++)
    {
        printf("%c出现了%d次\n", 'a' + i, pp[i]);
    }
}

void tongji(char *ss, int *pp)
{
    int len = strlen(ss);
    for(int i = 0; i < len; i++)
    {
        // 判断字符是否为小写字母
        if(ss[i] >= 'a' && ss[i] <= 'z')
        {
            // 统计出现次数
            pp[ss[i] - 'a']++;
        }
    }
}
``
编写一C程序统计一字符串中‘a’至‘z’26个小写字母各自出现在的次数。要求:小写字母的统计通过函数 void tongjichar ss int pp进行数据的输入输出及函数调用通过main函数进行。相关变量定义: void main char tt100; int pp26;……

原文地址: https://www.cveoy.top/t/topic/g9Zq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录