| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 324 人关注过本帖
标题:数组问题
只看楼主 加入收藏
tc12
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2012-11-8
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
数组问题
一组数组,(中间允许出现重复的数字不按顺序的输入1-49,不超过100个元素),然后在这组数组中找相同的数字,输出他们重复的次数,如果是没有出现在数组(1-49这个范围)的就被忽略,就是不显示在输出内容里!
请各位帮帮忙,谢谢了。。。。。。
搜索更多相关主题的帖子: 元素 
2012-11-11 11:42
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
收藏
得分:7 
最简单的方式就是循环比较了,就是效率太低

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2012-11-11 11:48
c语言DYY
Rank: 2
等 级:论坛游民
帖 子:51
专家分:44
注 册:2012-10-21
收藏
得分:7 
双重循环。。。
2012-11-11 12:06
tc12
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2012-11-8
收藏
得分:0 
回复 3楼 c语言DYY
程序代码:
#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;
}

可以帮我看下最后算频率那里哪里错了吗?????
谢谢了
2012-11-11 12:26
tc12
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2012-11-8
收藏
得分:0 
回复 2楼 pauljames
程序代码:
#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;
}

可以帮我看下哪里不对吗???谢谢了
2012-11-11 12:28
快速回复:数组问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014864 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved