Home > Back-end >  Help!!!!!!!!!! Brothers to see why I printed the first character always disappear
Help!!!!!!!!!! Brothers to see why I printed the first character always disappear

Time:09-20

# include
# define N 100
Void main (void)
{
Int I=0, j=0, n=0, t=0;
Int a [N].
Printf (" please enter the number of input digital \ n \ r ");
The scanf (" % d ", & amp; N);
Do
{
Printf (" please enter a number: \ n ");
The scanf (" % d ", & amp; A [I]);
i++;
}
While (a [I - 1] & gt;=0);

for(i=1; i the number of tripsFor (j=1; JIf (a [j] & gt; A [m + 1])
{
T=a, [j].//is produced using the variable tong two value swaps
A [j]=a, a + 1 bonus to [j].
A [m + 1]=t;
}

Printf (" sorted order is: \ n ");
For (I=3; i<=n; I++)
Printf (" % 5 d, "a [I]);

printf("\n");
return 0;
}
This is a matter of the order of the elements in an array output output first character always disappear


Results:
Please input the number of input digital
5
Please enter a number:
5
Please enter a number:
4
Please enter a number:
3
Please enter a number:
2
Please enter a number:
1
After sorting order is:
2, 3, 4,
Press any key to continue

CodePudding user response:

For (I=3; i<=n; Why do you want to start from 3 i++)? Don't start from 0

CodePudding user response:

 # include 

# define N 100

//void main (void)
Int main (void)
{
Int I=0, j=0, n=0, t=0;
Int a [N].
Printf (" please enter the number of input digital \ n \ r ");
The scanf (" % d ", & amp; N);
If # 1
While (I & lt; N) {
Printf (" please enter a number: \ n ");
The scanf (" % d ", & amp; A [I]);
If (a [I] <0)
break;
i++;
}
for (i=0; i For (j=0; J & lt; N - I - 1; J++)
If (a [j] & gt; + 1 a [j]) {
T=a, [j].
A [j]=a, a + 1 bonus to [j].
A [m + 1]=t;
}

Printf (" sorted order is: \ n ");
for (i=0; i Printf (" % 5 d, "a [I]);
# the else
/*
Do
{
Printf (" please enter a number: \ n ");
The scanf (" % d ", & amp; A [I]);
i++;
}
While (a [I - 1] & gt;=0);
*/


for(i=1; i the number of tripsFor (j=1; JIf (a [j] & gt; A [m + 1])
{
T=a, [j].//is produced using the variable tong two value swaps
A [j]=a, a + 1 bonus to [j].
A [m + 1]=t;
}

Printf (" sorted order is: \ n ");
For (I=3; i<=n; I++)
Printf (" % 5 d, "a [I]);
# endif
printf("\n");
return 0;
}

For your reference ~

Recommended substitute while the do... While, because if the n input is zero, then what is the result?
Sorting also have a question,
Output also has a problem, compare the code to find their own problems

CodePudding user response:

Programmers to count to start from 0 not 1

CodePudding user response:

reference 2 building self-confidence boy reply:
 # include 

# define N 100

//void main (void)
Int main (void)
{
Int I=0, j=0, n=0, t=0;
Int a [N].
Printf (" please enter the number of input digital \ n \ r ");
The scanf (" % d ", & amp; N);
If # 1
While (I & lt; N) {
Printf (" please enter a number: \ n ");
The scanf (" % d ", & amp; A [I]);
If (a [I] <0)
break;
i++;
}
for (i=0; i For (j=0; J & lt; N - I - 1; J++)
If (a [j] & gt; + 1 a [j]) {
T=a, [j].
A [j]=a, a + 1 bonus to [j].
A [m + 1]=t;
}

Printf (" sorted order is: \ n ");
for (i=0; i Printf (" % 5 d, "a [I]);
# the else
/*
Do
{
Printf (" please enter a number: \ n ");
The scanf (" % d ", & amp; A [I]);
i++;
}
While (a [I - 1] & gt;=0);
*/


for(i=1; i the number of tripsFor (j=1; JIf (a [j] & gt; A [m + 1])
{
T=a, [j].//is produced using the variable tong two value swaps
A [j]=a, a + 1 bonus to [j].
A [m + 1]=t;
}

Printf (" sorted order is: \ n ");
For (I=3; i<=n; I++)
Printf (" % 5 d, "a [I]);
# endif
printf("\n");
return 0;
}

For your reference ~

Recommended substitute while the do... While, because if the n input is zero, then what is the result?
Sorting also have a question,
Output also has a problem, compare the code to find your own problem
thank you

CodePudding user response:

reference weixin_41991157 reply: 3/f
programmer to count to start from 0 not 1
 freshman just learn a little meng force

CodePudding user response:

The
reference 1/f, Simple, Soft reply:
for (I=3; i<=n; Why do you want to start from 3 i++)? Don't start from 0
when starting from 0 results more unreliable just found a relative of the number 3 ha ha ha
  • Related