Home > Back-end >  Enter a binary number, the output of its 16 bit binary number.
Enter a binary number, the output of its 16 bit binary number.

Time:09-28

Subject is a binary number input, the output of its 16 bit binary number, the code on the DEV run perfect, but an error on the platform of school homework is invalid memory references, strives for the big show where there is a problem,
#include
Int main ()
{int n, I, j, k;
Static int a, [16].
The scanf (" % d ", & amp; N);
for(i=1; I<=16; I++)
{a [I]=n % 2; K=n/2; N=k; }
For (j=16; J> 0; J -)
Printf (" % d ", a [j]);
If (j==1) printf (" \ n ");
}

CodePudding user response:

What do you mean?
Enter a binary number, the output is a binary number??????

CodePudding user response:

You first make sure the array [16] a subscript from what to what end, should be from 0 to 15, but you use the 16, an array

CodePudding user response:

refer to the second floor qybao response:
you first make sure a [16] array subscript began to what end, what should be from 0 to 15, but you use 16, an array

And without crossing the line, his cycle from 1 to 16,

CodePudding user response:

for(i=1; I<=16; I++)
I maximum 16

A [16] is crossing the line

CodePudding user response:

An array ~ data crossing the line is undefined behavior, that may be running problem, also can go wrong ~

CodePudding user response:

reference CHXCHXKKK reply: 3/f
is not crossing the line, his cycle, from 1 to 16

Cycles that's right, but the array subscript fault, array subscript from 0 begin to calculate, so is 0 to 15
  • Related