c语言 5-9
1、
#include <stdio.h>
#define NUMBER 1000
int main(void)
{
int i, j, num, a[NUMBER], b[11] = {0};
do
{
printf("num = "); scanf("%d", &num);
if(num < 1 | num > NUMBER)
printf("range is 1-%d\n", NUMBER);
}
while(num < 1 | num > NUMBER);
for(i = 0; i < num; i++)
{
do
{
printf("NO.%d = ", i + 1); scanf("%d", &a[i]);
if(a[i] < 0 | a[i] > 100)
printf("the range is 0-100.\n");
}
while(a[i] < 0 | a[i] > 100);
b[a[i] / 10]++;
}
printf("====distribution plot====\n");
int max = b[0];
for(i = 0; i < 11; i++)
{
if(b[i] > max)
max = b[i];
}
printf("max = %d\n", max);
for(i = 0; i < max; i++)
{
for(j = 0; j < 11; j++)
{
if(b[j] >= max - i)
{
printf(" *");
}
else
{
printf(" ");
}
}
putchar('\n');
}
puts("--------------------------------------------------------");
for(i = 0; i < 11; i++)
{
printf("%5d", i * 10);
}
putchar('\n');
return 0;
}