Home Article Practice 输入学生分数,显示分布情况的代码

输入学生分数,显示分布情况的代码

2024-04-10 16:31  views:400  source:淺唱,流年    

#include<stdio.h>
#define NUMBER 100
int main(void){
int num,i,j;
int fenshu[NUMBER];
int fenbu[11]={0};
do{
scanf("%d",&num);
}while(num<0||num>100);
printf("请输入%d人的分数\n",num);
for(i=0;i<num;i++){
printf("fenshu[%d]:",i);
do{
scanf("%d",&fenshu[i]);
if(fenshu[i]<1||fenshu[i]>100)
printf("\a请输入1~100的数:");
}while (fenshu[i]<1||fenshu[i]>100);
fenbu[fenshu[i]/10]++;
}
puts("-----分布图-----");
puts("100:") ;
for(j=0;j<fenbu[10];j++)
putchar('*');
putchar('\n');
for(i=9;i>=0;i--){
printf("%3d~%3d:",i*10,i*10+9);
for(j=0;j<fenbu[i];j++)
putchar('*');
putchar('\n');
}
return 0;
}



Disclaimer: The above articles are added by users themselves and are only for typing and communication purposes. They do not represent the views of this website, and this website does not assume any legal responsibility. This statement is hereby made! If there is any infringement of your rights, please contact us promptly to delete it.

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)