• c语言中设置数组元素的个数


    c语言中数组元素的个数。

    虽然通过对象式宏修改数组元素个数非常的方便,但是每次都需要对程序进行修改,然后重新编译执行。因此,我们可以定义一个比较大的数组,然后从头开始仅使用其中需要的部分。

    1、

    #include <stdio.h>
    
    #define NUMBER 1000
    
    int main(void)
    {
        int i, j, num, a[NUMBER], b[11] = {0};
        printf("student number: ");
        do
        {
            scanf("%d", &num);
            if(num < 1 | num > 1000)
                printf("the range of number is 1-%d.\n", NUMBER);
        }
        while(num < 1 | num > 1000);
        
        printf("students score: \n");
        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]++;
        }
        
        printf("---distribution plot---\n");
        printf("      100: ");
        for(i = 0; i < b[10]; i++)
        {
            putchar('*');
        }
        putchar('\n');
        
        for(i = 9; i >= 0; i--)
        {
            printf("%3d - %3d: ", i * 10 , i * 10 + 9);
            for(j = 0; j < b[i]; j++)
            {
                putchar('*');
            }
            putchar('\n');
        }
        return 0;
    }

  • 相关阅读:
    BZOJ3543: [ONTAK2010]Garden
    python初识面向对象
    python装饰器
    python递归函数及二分法查找
    python内置函数及匿名函数
    生成器和生成器函数以及各种推导式
    第一类对象 函数名 变量名
    函数的进阶
    Python初始函数
    Python文件操作
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14717466.html
Copyright © 2020-2023  润新知