c语言编程练习题:7-90 统计字符
作者:yunjinqi   类别:    日期:2023-05-31 10:18:11    阅读:121 次   消耗积分:0 分    

image.png

#include <stdio.h>
int main(){
    char ch;
    int letter_num=0;
    int blank_num=0;
    int digit_num=0;
    int other_num=0;
    char str[10];
	for(int j=0;j<10;j++) str[j]=getchar();
    
    for (int i=0;i<10;i++){
        ch = str[i];
        if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')){
            letter_num++;}
        else if(ch >= '0' && ch <= '9'){
            digit_num++;
            }
        else if(ch==' '||ch == '\n'){
            blank_num++;
        }else{
            other_num++;
        }
    }
    printf("letter = %d, blank = %d, digit = %d, other = %d",letter_num,blank_num,digit_num,other_num);
    
return 0;
}


版权所有,转载本站文章请注明出处:云子量化, http://www.woniunote.com/article/215
上一篇:c语言编程练习题:7-89 阶梯电价
下一篇:c语言编程练习题:7-91 输出闰年