第1个回答 2006-06-25
#include<stdio.h>
void main()
{ int a[5]={0,0,0,0,0},n,i;
for(i=1;i<50;i++)
{ scanf("%d",&n);
if(n!=-1)
a[n]++;
else break;
}
for(i=0;i<5;i++)
printf("%d有%d个\n",i,a[i]);
}
第2个回答 2006-06-25
原代码如下:(经过测试)
#include <stdio.h>
int i,i0,i1,i2,i3,i4;
int main()
{
while(i != -1)
{
scanf("%d",&i);
switch(i){
case 0:
i0++;
break;
case 1:
i1++;
break;
case 2:
i2++;
break;
case 3:
i3++;
break;
case 4:
i4++ ;
break;
default:
break;
}
}
printf("\nnumber 0 : %d \n",i0);
printf("number 1 : %d \n",i1);
printf("number 2 : %d \n",i2);
printf("number 3 : %d \n",i3);
printf("number 4 : %d \n",i4);
}