博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C 语言 习题 1-14
阅读量:4687 次
发布时间:2019-06-09

本文共 1015 字,大约阅读时间需要 3 分钟。

练习 1-14 编写一个程序,打印输入中各个字符出现频度的直方图。

 

1 #include 
2 3 /* count digits, white space, others */ 4 5 int main(int argc, char const *argv[]) 6 { 7 int c, i, j, nwhite, nother; 8 int ndigit[10]; 9 10 nwhite = nother = 0;11 for (i = 0; i < 10; ++i) {12 ndigit[i] = 0;13 }14 15 while ((c = getchar()) != EOF) {16 if (c >= '0' && c <= '9') {17 ++ndigit[c-'0'];18 } else if (c == ' ' || c == '\n' || c == '\t') {19 ++nwhite;20 } else {21 ++nother;22 }23 }24 25 for (i = 0; i < 10; ++i) {26 printf("%d:", i);27 for (j = 0; j < ndigit[i]; ++j) {28 printf("*");29 }30 printf("\n");31 }32 printf("w:");33 for (i = 0; i < nwhite; ++i) {34 printf("*");35 }36 printf("\no:");37 for (i = 0; i < nother; ++i) {38 printf("*");39 }40 printf("\n");41 42 return 0;43 }

 

转载于:https://www.cnblogs.com/berthua/p/7694789.html

你可能感兴趣的文章
Git for Android Studio 学习笔记
查看>>
pip 警告!The default format will switch to columns in the future
查看>>
Arrays类学习笔记
查看>>
实验吧之【天下武功唯快不破】
查看>>
2019-3-25多线程的同步与互斥(互斥锁、条件变量、读写锁、自旋锁、信号量)...
查看>>
win7-64 mysql的安装
查看>>
dcm4chee 修改默认(0002,0013) ImplementationVersionName
查看>>
maven3在eclipse3.4.2中创建java web项目
查看>>
发布时间 sql语句
查看>>
黑马程序员 ExecuteReader执行查询
查看>>
记一些从数学和程序设计中体会到的思想
查看>>
题目1462:两船载物问题
查看>>
POJ 2378 Tree Cutting(树形DP,水)
查看>>
第二冲刺阶段个人博客5
查看>>
UVA 116 Unidirectional TSP (白书dp)
查看>>
第三方测速工具
查看>>
MySQL 网络访问连接
查看>>
在aws ec2上使用root用户登录
查看>>
数据访问 投票习题
查看>>
CIO知识储备
查看>>