c语言5-9中录入指定人数成绩、统计成绩分布

 

1、

#include <stdio.h>
# define NUMBER 80

int main(void)
{
    int a[NUMBER];
    int number;
    
    puts("please input the number of the student.");
    do
    {
        printf("number of student = ");
        scanf("%d", &number);
        if (number < 1 | number > NUMBER)
        {
            printf("\athe san of number is 1-%d\n", NUMBER);
        }
    }
    while ( number < 1 | number > NUMBER);
    
    printf("please input %d student scores.\n", number);
    int i;
    for (i = 0; i < number; i++)
    {
        do
        {
            printf("%dst = ", i + 1);
            scanf("%d", &a[i]);
            if (a[i] < 0 | a[i] > 100)
                printf("the score range is 0-100\n");
        }
        while (a[i] < 0 | a[i] > 100);    
    }
    puts("-----\n-----\n-----");
    
    int b[11] = {0};
    for (i = 0 ; i < number; i++)
    {
        if (a[i]/10 == 0)
        b[0]++;
        if (a[i]/10 == 1)
        b[1]++;
        if (a[i]/10 == 2)
        b[2]++;
        if (a[i]/10 == 3)
        b[3]++;
        if (a[i]/10 == 4)
        b[4]++;
        if (a[i]/10 == 5)
        b[5]++;
        if (a[i]/10 == 6)
        b[6]++;
        if (a[i]/10 == 7)
        b[7]++;
        if (a[i]/10 == 8)
        b[8]++;
        if (a[i]/10 == 9)
        b[9]++;
        if (a[i]/10 == 10)
        b[10]++;
    }
    
    puts(" destribution plot  ");
    printf("   100: ");
    for (i = 0; i < b[10]; i++)
        putchar('*');
        putchar('\n'); 
    
    int j;    
    for (i = 9; i >=0; i--)
    {
        printf("%d-%d", i * 10, i * 10 + 10);
        putchar(':');
        for (j = 0; j < b[i]; j++)
            putchar('*');
            putchar('\n');
     } 
    return 0;
    
}

↓ 

#include <stdio.h>
#define NUMBER 80

int main(void)
{
    int a[NUMBER];
    int number;
    puts("please input the number of students.");
    do
    {
        printf("student number = ");
        scanf("%d", &number);
        if (number < 1 | number > NUMBER)
            printf("the scan of student is 1-%d\n", NUMBER);
    }while (number < 1 | number > NUMBER);
    
    printf("please input the score of the %d students.\n", number);
    int i;
    int b[11] = {0};
    for (i = 0; i < number; i++)
        do
        {
            printf("%dst = ", i + 1);
            scanf("%d", &a[i]);
            if (a[i] < 0 | a[i] > 100)
                puts("the scan of the score is 0-100.");
            else
            b[a[i]/10]++;
        }while (a[i] < 0 | a[i] > 100);
    
    puts("distribution plot.");
    int j;
    for (i = 0; i < 10; i++)
        {    printf("%d-%d",i * 10, i * 10 + 10);
            putchar(':');
            for (j = 0; j < b[i]; j++)
                {        
                    putchar('*');
                }
            putchar('\n');
        }
    printf("100:");
    for (i = 0; i < b[10]; i++)
        putchar('*');
        putchar('\n');
    return 0;
}

↓ 

#include <stdio.h>
#define NUMBER 80

int main(void)
{
    int a[NUMBER];
    int number;
    puts("please input the number of the students.");
    do
    {
        printf("number = ");scanf("%d", &number);
        if (number < 0 | number > NUMBER)
            printf("the scan of number is 1-%d\n", NUMBER);
    }while (number < 0 | number > NUMBER);
    
    puts("please input the score of the students");
    
    int i;
    int b[11] = {0};
    for (i = 0; i < number; i++)
    {
        do
        {
            printf("%dst = ", i + 1); scanf("%d", &a[i]);
            if (a[i] < 0 | a[i] > 100)
                puts("the scan of score is 0-100.");
        }while (a[i] < 0 | a[i] > 100);
        b[a[i]/10]++;
    }
    
    puts("distribution plot.");
    printf("  100:");
    for (i = 0; i < b[10]; i++)
        putchar('*');
  putchar('\n');
int j; for (i = 9; i >=0; i--) { printf("%d-%d:",i * 10, i * 10 + 10); for (j = 0; j < b[i]; j++) { putchar('*'); } putchar('\n'); } return 0; }

 

↓ 

#include <stdio.h>
#define NUMBER 80

int main(void)
{
    int a[NUMBER];
    int number;
    puts("please input the number of the students.");
    do
    {
        printf("number = "); scanf("%d", &number);
        if (number < 1 | number > NUMBER)
            printf("the scan of the number is 1-%d.\n", NUMBER);
    }while (number < 1 | number > NUMBER);
    
    printf("please input the scores of the %d student.\n", number);
    int i;
    int b[11] = {0};
    for (i = 0; i < number; i++)
    {
        do
        {
            printf("%dst = ", i + 1); scanf("%d", &a[i]);
            if (a[i] < 0 | a[i] > 100)
                printf("the scan of the score is 1-100.\n");
        }while (a[i] < 0 | a[i] > 100);
        b[a[i]/10]++;
    }
    puts("distribution plot.\n-------\n-------");
    int j;
    for (i = 0; i < 10; i++)
    {
        printf("%d-%d:", i * 10, i * 10 + 10);
        for (j = 0; j < b[i]; j++)
            putchar('*');
            putchar('\n');
    }
    printf("100:");
    for (i = 0; i < b[10]; i++)
        putchar('*');
        putchar('\n');
    return 0;
}

↓ 

#include <stdio.h>

int main(void)
{
    int i;
    int v[11] = {0,1,1,2,2,1,3,1,2,1,1};
    int max = v[0];
    for (i = 0; i < 11; i++)
    {
        if (v[i] > max)
        max = v[i];
    }
    
    int j;
    for (i = 0; i < max; i++)
    {
        for (j = 0; j < 11; j++)
        {
            if (v[j] >= max - i)
            {
            printf(" ");
            printf(" ");
            putchar('*');
            printf(" ");
            printf(" ");
            }
            else
            {
            printf(" ");
            printf(" ");
            printf(" ");
            printf(" ");
            printf(" ");
            }
        }
        putchar('\n');
    }
    puts("-------------------------------------------------------");
    for (i = 0; i < 11; i++)
    printf("  %d ", i * 10);
    return 0;
}

↓ 

#include <stdio.h>
#define NUMBER 80

int main(void)
{
    int a[NUMBER];
    int number;
    puts("please input the number of the students.");
    do
    {
        printf("number = "); scanf("%d", &number);
        if (number < 1 | number > NUMBER)
            printf("\athe scan of the number is 1-%d.\n", NUMBER);
    }while (number < 1 | number > NUMBER);
    
    printf("please input the score of %d student.\n", number);
    int i;
    int b[11] = {0};
    for (i = 0; i < number; i++)
    {
        do
        {
            printf("%dst = ", i + 1); scanf("%d", &a[i]);
            if (a[i] < 0 | a[i] > 100)
            printf("\athe scan of score is 0-100.\n");
        }while (a[i] < 0 | a[i] > 100);
        b[a[i]/10]++;
    }
    
    int max;
    for (i = 0; i < 11; i++)
    {
        if (b[i] > max)
        max = b[i];
    }
    
    int j;
    for (i = 0; i < max; i++)
    {
        for (j = 0; j < 11; j++)
        {
            if (b[j] >= max - i)
            {
            printf(" ");
            printf(" ");
            putchar('*');
            printf(" ");
            printf(" ");
            }
            else
            {
            printf(" ");
            printf(" ");
            printf(" ");
            printf(" ");
            printf(" ");
            }
        }
        putchar('\n');
    }
    puts("-------------------------------------------------------");
    for (i = 0; i < 11; i++)
    printf("  %d ", i * 10);
    return 0;
    
    
}

 

posted @ 2021-02-04 18:48  小鲨鱼2018  阅读(436)  评论(0编辑  收藏  举报