微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

计算每个数字,空白字符空白,制表符,换行符和所有其他字符的出现次数

#include <stdio.h>  

   int main() 
   {  
       int c, nwhite= 0, nother= 0;  
       int ndigit[10];  

       for (int 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 (int i = 0; i < 10; ++i)  
           printf( %d, ndigit[i]);  
       printf(, white space = %d, other = %d\n, nwhite, nother);  
   }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐