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;
}

运行截图:

相关推荐
听风lighting4 小时前
1. C++ WebServer项目分享
linux·c语言·c++·设计模式·嵌入式·webserver
int型码农5 小时前
数据结构第八章(五)-外部排序和败者树
c语言·数据结构·算法·排序算法
ghie90907 小时前
Ubuntu编译ffmpeg解决错误:ERROR: avisynth/avisynth_c.h not found
c语言·ubuntu·ffmpeg
iCxhust8 小时前
PC16550 UART接收中断处理完整示例代码
c语言·开发语言·stm32·单片机·嵌入式硬件
C++ 老炮儿的技术栈11 小时前
C++实现手写strlen函数
大数据·c语言·c++·编辑器
今日待办13 小时前
Arduino Nano 33 BLE Sense Rev 2开发板使用指南之【外设开发】
c语言·单片机·嵌入式硬件·mcu
AI+程序员在路上13 小时前
ABI与API定义及区别
c语言·开发语言·c++
森焱森13 小时前
驱动开发,队列,环形缓冲区:以GD32 CAN 消息处理为例
c语言·单片机·算法·架构
程序员弘羽16 小时前
extern关键字:C/C++跨文件编程利器
c语言·开发语言·c++
凌肖战1 天前
力扣网C语言编程题:三数之和
c语言·算法·leetcode