C/C++教程

c语言 5-9

本文主要是介绍c语言 5-9,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1、

#include <stdio.h>

#define NUMBER 1000

int main(void)
{
    int i, j, num, a[NUMBER], max, b[11] = {0};
    do
    {
        printf("num = "); scanf("%d", &num);
        if(num < 1 | num > NUMBER)
            printf("the range of num is 1-%d\n",NUMBER);
    }
    while(num < 1 | num > NUMBER);
    
    puts("please input the scores of the students.");
    for(i = 0; i < num; i++)
    {
        do
        {
            printf("NO.%d = ", i + 1); scanf("%d", &a[i]);
            if(a[i] < 0 | a[i] > 100)
                puts("the range of score is 0-100.");
        }
        while(a[i] < 0 | a[i] > 100);
        
        b[a[i] / 10]++;
    }
    max = b[0];
    for(i = 0; i < 11; i++)
    {
        if(b[i] > max)
            max = b[i];
    }

    printf("max = %d\n", max);
    puts("====================distribution plot==============================");
    for(i = max; i > 0; i--)
    {
        for(j = 0; j < 11; j++)
        {
            if(b[j] >= i)
                printf("    *");
            else
                printf("     ");
        }
        putchar('\n');
    }
    
    puts("---------------------------------------------------------------------");
    for(i = 0; i < 11; i++)
    {
        printf("%5d", i * 10);
    }
    putchar('\n');
    return 0;
}

 

这篇关于c语言 5-9的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!