C语言作业的题目,不会做

2025-03-24 14:51:18
推荐回答(1个)
回答1:

#include
#include
void fun(int a[],int n)
{
int i,b[6],pri[5]={100,200,300,400,500},t; //数组b开小了,导致下面的循环出不来
for(i=0;i<6;i++)
b[i]=0;
for(i=0;i {
t=a[i]/100; //优化了下
b[t>4?5:t]++;
}
printf("the price under 100 yuan: %d\n",b[0]);
for(i=0;i<4;i++) //优化了下
printf("the price for %d to %d yuan: %d\n",pri[i],pri[i+1],b[i+1]);
printf("the price more than 500 yuan: %d\n",b[5]);
}
void main()
{
int a[20],i,n=20;
printf("the price of %d input\n",n);
for(i=0;i scanf("%d",a+i);
fun(a,n);
}

题目中的代码肯定是错误的。。。