12、c程序中编程,统计一行中数字字符的个数。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
int main()
{
    int j = 0,c=0;
    //char s[100]
    char s[100]={'8','a','a'};    
    //puts("请输入字符串:");
    //gets(s);
    //s={'1','2','3','1','a','e','q'};
    
    for (int i = 0; i < strlen(s); i++)
    {
        if ((s[i]<='9')&&(s[i]>='0')){
            j++;
        }
        else{
            c++;
        }
    }
    printf("数字字符的个数是:%d\n", j);
    printf("字符的个数是:%d\n", c);
    //system("pause");
    return 0;
}

 

posted @ 2017-12-11 16:29  凤凰汇郭  阅读(733)  评论(0编辑  收藏  举报