标题:求助数组自加运行逻辑
取消只看楼主
gonewwade
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2017-5-11
 问题点数:0 回复次数:3 
求助数组自加运行逻辑
统计各数字、空白符、其他字符出现次数
#include <stdio.h>
main()
{
    int c,i,nwhite,nother;
    int ndigit[10];
    nwhite=nother=0;
    for(i=0;i<10:++i)
        if(c>='0'&&c<='9')
             ++ndigit[c-'0'];
        else if(c==''||c=='\n'||c=='\t')
             ++nwhite;
        else
             ++nother;
        printf("digits=");
        for(i=0;i<10;++i)
            printf("%d",ndigit[i]);
        printf(",white space=%d,other=%d\n",nwhite,nother);  
}
请问该段程序中if(c>='0'&&c<='9')
                  ++ndigit[c-'0'];
条件如果成立,数组自+运行逻辑是什么?
搜索更多相关主题的帖子: white include 统计 
2017-05-11 15:47
gonewwade
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2017-5-11
得分:0 
回复 2楼 吹水佬
少写了一句while((c=getchar())!=EOF)在if语句之前
2017-05-11 16:19
gonewwade
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2017-5-11
得分:0 
回复 3楼 gonewwade
#include <stdio.h>
 main()
 {
     int c,i,nwhite,nother;
     int ndigit[10];
     nwhite=nother=0;
     for(i=0;i<10:++i)
         ndigit[i]=0;
     while((c=gerchar())!=EOF)
         if(c>='0'&&c<='9')
              ++ndigit[c-'0'];
         else if(c==''||c=='\n'||c=='\t')
              ++nwhite;
         else
              ++nother;
         printf("digits=");
         for(i=0;i<10;++i)
             printf("%d",ndigit[i]);
         printf(",white space=%d,other=%d\n",nwhite,nother);  
 }
2017-05-11 16:21
gonewwade
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2017-5-11
得分:0 
回复 5楼 吹水佬
如果我连续输入了0-9,那么这段语句是怎样运行的呢,是累加到10么?
2017-05-11 16:44



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-476922-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.940473 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved