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; }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM