C语言——有一篇文章,共有 3 行文字,每行有 80 个字符。要求分别统计出其中英文大写字母、小写字母、数字、空格以及其他字符的个数

完整代码:

复制代码
/* 有一篇文章,共有 3 行文字,每行有 80 个字符。要求分别统计出其中英文大写字母、
小写字母、数字、空格以及其他字符的个数*/

#include<stdio.h>
int main(){
    //创建一篇这样的文章到二维字符数组中
    char str[3][80] = {
        "The Quick Brown Fox Jumps Over 123 Lazy Dogs. A Test Sentence for Char Count.",
        "In This Line, We Have 4567 Numbers Mixed with Special Characters and Spaces.",
        "How Many UPPERCASE Letters, lowercase letters, 789 Numbers, and %* Punctuation."
    };
    //定义所求的结果
    int bigLetter=0,littleLetter=0,number=0,blank=0,another=0;
    //遍历所有字符求解
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 80; j++)
        {
            //判断字符所属类别
            int c=str[i][j];
            if (c>='A'&&c<='Z')
            {
                bigLetter++;
            }
            else if (c>='a'&&c<='z')
            {
                littleLetter++;
            }
            else if (c==' ')
            {
                blank++;
            }
            else if (c>='0'&&c<='9')
            {
                number++;
            }
            else{
                another++;
            }
        }
    }
    printf("大写字母个数:%d\n小写字母个数:%d\n数字个数:%d\n空格个数:%d\n其他字符个数:%d",bigLetter,littleLetter,number,blank,another);
    return 0;
}

运行截图:

相关推荐
norlan_jame16 小时前
C-PHY与D-PHY差异
c语言·开发语言
czy878747517 小时前
除了结构体之外,C语言中还有哪些其他方式可以模拟C++的面向对象编程特性
c语言
m0_5312371717 小时前
C语言-数组练习进阶
c语言·开发语言·算法
Z9fish21 小时前
sse哈工大C语言编程练习23
c语言·数据结构·算法
代码无bug抓狂人21 小时前
C语言之单词方阵——深搜(很好的深搜例题)
c语言·开发语言·算法·深度优先
CodeJourney_J21 小时前
从“Hello World“ 开始 C++
c语言·c++·学习
枫叶丹41 天前
【Qt开发】Qt界面优化(七)-> Qt样式表(QSS) 样式属性
c语言·开发语言·c++·qt
with-the-flow1 天前
从数学底层的底层原理来讲 random 的函数是怎么实现的
c语言·python·算法
Sunsets_Red1 天前
P8277 [USACO22OPEN] Up Down Subsequence P 题解
c语言·c++·算法·c#·学习方法·洛谷·信息学竞赛
小刘爱玩单片机1 天前
【stm32简单外设篇】- 测速传感器模块(光电)
c语言·stm32·单片机·嵌入式硬件