当中程序练习。输出C直方图
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#include <stdio.h> main() { int a[30];
int i,j,c;
j = i = 0;
for (i = 0; i < 30; i++){
a[i] = 0;
}
while ((c = getchar ()) != '#' ){
if (c > '0' && c<= '30' )
++a[c - '0' ];
}
for (i = 0 ;i < 30; i++){
if (a[i] != 0){
printf ( "\n%d" ,i);
}
for (j = 0; j < a[i];j++){
putchar ( '*' );
}
putchar ( '\n' );
}
return 0;
}
|
本文转自 小罗ge11 51CTO博客,原文链接:http://blog.51cto.com/xiaoluoge/1786826,如需转载请自行联系原作者