輸入一個字符串,統計英文字母、空格、數字和其它字符的個數


#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
void check_count();
int main() {
    
    check_count();
    return 0;
}
void check_count() {
    int count_digit = 0, count_letter = 0, count_space = 0, count_other = 0;
    char c;
    printf("請輸入一串字符!\n");
    while ((c = getchar()) != '\n') {
        if (c >= 'a' && c <= 'z' || c >= 'A' &&c <= 'Z') {
            count_letter++;
        }
        else if (c == ' ') {
            count_space++;
        }
        else if (c >= '0' && c <= '9') {
            count_digit++;
        }
        else {
            count_other++;
        }


    }
    printf("\n統計結果:\n英文字母=%d\n空格=%d\n整數=%d\n其他字符=%d\n\n", count_letter, count_space, count_digit, count_other);
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM