| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1964 人关注过本帖
标题:统计各个数字,空白符,以及其他字符出现的次数
取消只看楼主 加入收藏
stanlc
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-11-5
结帖率:50%
收藏
 问题点数:0 回复次数:2 
统计各个数字,空白符,以及其他字符出现的次数
#include <stdio.h>

int main(void)
{
  int c,i,nwhite,nother;
  int ndigit[10];

  nwhite = nother = 0;
  
  for(i = 0; i < 10; ++i)
  {
    ndigit[i] = 0;

    while((c = getchar()) != 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);
  }
  return 0;
}

结果出现乱码。。数字次数不对 其他都对的

[ 本帖最后由 stanlc 于 2013-11-5 22:43 编辑 ]
搜索更多相关主题的帖子: 统计 include 
2013-11-05 22:41
stanlc
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-11-5
收藏
得分:0 
回复 2楼 南国神画
嗯,确实数字查找方法错了
2013-11-06 22:44
stanlc
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-11-5
收藏
得分:0 
回复 3楼 pangshch
谢谢~已经解决了!
2013-11-06 22:45
快速回复:统计各个数字,空白符,以及其他字符出现的次数
数据加载中...
 
   



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

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