数组问题
一组数组,(中间允许出现重复的数字不按顺序的输入1-49,不超过100个元素),然后在这组数组中找相同的数字,输出他们重复的次数,如果是没有出现在数组(1-49这个范围)的就被忽略,就是不显示在输出内容里!请各位帮帮忙,谢谢了。。。。。。
程序代码:
#include <stdio.h>
int main (void)
{
int i=0,j=0,n=0,a[100],x,b=0,max=1;
int num[49],l=0,k=1;
printf("Enter the balls that are drawn from the machine: \n");
do
{
scanf("%d",&x);
if (x>0&&x<49){
a[i]=x;
i++;
}
}while (i<100 && x>0 && x<49);
printf("\n\nThe values from 1st ball to the 6th ball are: \n");
for(j=0;j<6;j++)
printf("%d ",a[j]);
printf("\n\nThe 10th,20th and 30th balls: \n");
printf("10th ball: %d\n20th ball: %d\n30th ball:%d\n",a[9],a[19],a[29]);
for(j=0;j<i;j++){
if (a[j] >40)
b++;
}
printf("\nThe values are great than 40:%d\n",b);
for(n=0;n<100;n++)
{
if(max<a[n])
max=a[n];
}
printf("\nThe max vaule is : %d\n", max);
for (l=0;l<100;l++)//频率
num[a[l]-1]++;
for(k=1;k<=49;k++)
printf("ball %d was drawn %d times",k,num[k]);
return 0;
}
程序代码:
#include <stdio.h>
int main (void)
{
int i=0,j=0,n=0,a[100],x,b=0,max=1;
int num[49],l=0,k=1;
printf("Enter the balls that are drawn from the machine: \n");
do
{
scanf("%d",&x);
if (x>0&&x<49){
a[i]=x;
i++;
}
}while (i<100 && x>0 && x<49);
printf("\n\nThe values from 1st ball to the 6th ball are: \n");
for(j=0;j<6;j++)
printf("%d ",a[j]);
printf("\n\nThe 10th,20th and 30th balls: \n");
printf("10th ball: %d\n20th ball: %d\n30th ball:%d\n",a[9],a[19],a[29]);
for(j=0;j<i;j++){
if (a[j] >40)
b++;
}
printf("\nThe values are great than 40:%d\n",b);
for(n=0;n<100;n++)
{
if(max<a[n])
max=a[n];
}
printf("\nThe max vaule is : %d\n", max);
for (l=0;l<100;l++)//频率
num[a[l]-1]++;
for(k=1;k<=49;k++)
printf("ball %d was drawn %d times",k,num[k]);
return 0;
}