且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用C编写程序以查找用户输入的数字是否在数组中重复?

更新时间:2023-02-10 19:12:22

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



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

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

掌握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>