当中程序练习。输出C直方图
#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; }
本文出自 “小罗” 博客,请务必保留此出处http://xiaoluoge.blog.51cto.com/9141967/1786826
原文地址:http://xiaoluoge.blog.51cto.com/9141967/1786826