如何使用C编写程序以查找用户输入的数字是否在数组中重复? [英] How do I write a program using C to find if numbers entered by user are repeated in arrays?

查看:86
本文介绍了如何使用C编写程序以查找用户输入的数字是否在数组中重复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写代码,以便我可以制作2个数组并从0填充它们然后比较它们以找出重复数据

如何在我知道的地方制作数组什么是它的输入,我如何将它与另一个randomely输入的数组进行比较?

i试图制作两个数组并比较它们但是我找不到根据我填充第一个数组的方法选择..



我尝试过:



I am tryin to write a code so that i can make 2 arrays and fill them both from 0 and then compare them both to find out the repeats
how can i make a array where i know what's the input in it and how do i compare it with another array which is randomely inputted?
i have tried to make two arrays and compare them but i cant find a way to fill up first array according to my choice..

What I have tried:

#include<stdio.h>
#include<conio.h>
void main()
{
int i,a,b,c[5],d[5];

    printf("enter a number");

    scanf("%",&d);

    for(i=0;i<5;i++)
    {

       scanf("%d",&c[i]);

         for(i=0;i<5;i++);
         {

            scanf("%d",&d[i]);

            if(c[i]==d[i])
            {

                printf("the repeated digits are %d");
            }

        }

    }

   getch();
}

推荐答案

您应该学习尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。



调试器允许你跟踪执行逐行检查变量,你会看到它有一个停止做你期望的点。

调试器 - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - A初学者指南 [ ^ ]



你应该试试这个,它应该更接近你的意愿。

You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

You should try this, it should be closer to your wishes.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,a,b,c[5],d[5];
 
    printf("enter a number");
 
    scanf("%",&d);
 
    // read the 5 c
    for(i=0;i<5;i++)
    {
        scanf("%d",&c[i]);
    }
 
    // read the 5 d
     for(i=0;i<5;i++);
     {

        scanf("%d",&d[i]);
     }
 
    // compare c and d ....
    if(c[i]==d[i])
    {

        printf("the repeated digits are %d");
    }

 
   getch();
}</conio.h></stdio.h>


这篇关于如何使用C编写程序以查找用户输入的数字是否在数组中重复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆