C language program error, don t know why

Updated on healthy 2024-02-09
4 answers
  1. Anonymous users2024-02-05

    That's it!

    #include

    int digit(int min,int max,int x);

    void main (void)

    int max,min,x;

    printf("Enter the number x:, which you want to find");

    scanf("%d",&x);

    max=9;

    min=0;

    digit(min,max,x);

    scanf( "%d", &x );

    int digit(int min,int max,int x)int m=(max+min)/2;

    int a[10]=;

    if( x> a[m])

    digit(m,max,x);

    return 0;

    if( x < a[m] )

    digit(min,m,x);

    return 0;

    if(x=a[m])

    printf("x is the %d number in the series",m);

    return 0;

    Analyze the reason: because the digit loop calls itself, is it in the stack, m is changed?

    Take a look at the result after adding the debug information: (not there" and "add return 0 afterward") Enter the number x:5 you want to find

    x is the 5th number in the sequence.

    x < a[m]x is the sixth number in the sequence.

    x > a[m]x is the fourth number in the sequence.

    Identification result: The value of the variable m in the stack changes several times due to the loop calling itself, so just use the program I gave you!

  2. Anonymous users2024-02-04

    The main thing is if(x=a[m]), the value in if is not equal to 0, so it causes multiple printfs, which should be changed to.

    if(x==a[m])

    printf("x is the %d number in the series",m);

  3. Anonymous users2024-02-03

    Add return to the method of the first two if blocks

  4. Anonymous users2024-02-02

    In C, just because a program doesn't report an error doesn't mean it's necessarily correct. Sometimes, a program may have a logical error or a runtime error that prevents the program from executing or the output does not meet expectations. Here are some common reasons why a program cannot be executed:

    1.The program is stuck in an endless loop: The program has an endless loop somewhere, making it impossible for the program to continue to execute downwards. If the program doesn't seem to end, you can check if the program has an endless loop.

    2.Memory leak: When the program uses dynamic memory allocation functions (such as malloc and calloc) to open up memory space, it does not release the allocated memory space in time, resulting in memory leakage.

    A memory leak will lead to a waste of system memory resources, and eventually cause the program to be unable to continue to execute.

    3.Array out-of-bounds: When the program accesses the array element, it exceeds the legal index range of the array, causing the program to crash or the output does not meet expectations.

    4.Crash or abnormality: The program crashes or is abnormal during execution, resulting in the program being unable to execute smoothly. This situation requires a debugging tool to find the problem and fix it.

    The above are some common reasons that cause the program to fail to execute, you can check whether your program has the above problems according to the actual situation. Also, if you're not sure what's wrong with your program, consider using a debugger to help you figure out what's wrong and fix it.

Related questions
4 answers2024-02-09

Cite month[12][10]; Wrong. Without the element month[12][10], up to month[11][9], and the pointer p is useless. There's also the deletion of all your +10-level corresponding *. >>>More

6 answers2024-02-09

Hello. Know the value of wealth].

1 New users log in for the first time 20 Complete the activation of the account2 Be 20 Bounty Points The person who asked the question is, or is selected by voting, will receive the 20 Bounty Points set by the system automatically given by the system. >>>More

9 answers2024-02-09

Overall, it's okay, but due to the recent hardware changes, there are still some that aren't perfect. Here are a few suggestions for you:: >>>More

16 answers2024-02-09

It's called Peeled Fish.

How to make the fish with the sauce of lemon flavor. >>>More

8 answers2024-02-09

You say [I don't want me to mess around like this] the first thing you have to do is to delete your mental activity, your brain, and your mind itself as all kinds of garbage and distractions. Start again, pay attention, you have to understand my words correctly, it will be more beneficial to you, and the power effect will be more rewarding. I'm not scolding you, I'm just pointing out the exact decisions you should have made about all the good and bad things in everyone >>>More