Home > Back-end >  Questions about an array of minimum output
Questions about an array of minimum output

Time:09-18

#include
Int main ()
{
Int n, I, min, a, [999].
The scanf (" % d ", & amp; n);
for(i=0; IThe scanf (" % d ", & amp; A [I]);
for(i=1; I{
If (a [I - 1] A [I]=a, [I - 1].
}
Printf (" % d ", a [I]);
}
Why can't this function correct output n number of minimum, give advice or comments please bosses!!!!!!

CodePudding user response:

Do you want to order? Don't take order, no exchange, directly from a variable to hold the minimum value

CodePudding user response:

Because you just compare the adjacent two elements, non-adjacent nothing, so the result of natural right
Instead of
Min=a, [0].//min take the value of the first element
for (i=1; IIf (min> A [I])//and then each element with min than
Min=a, [I].
Printf (" % d ", min);

CodePudding user response:

refer to the second floor qybao response:
because you just compare the adjacent two elements, non-adjacent than, so the result of natural right
Instead of
Min=a, [0].//min take the value of the first element
for (i=1; IIf (min> A [I])//and then each element with min than
Min=a, [I].
Printf (" % d ", min);
to start from scratch, each adjacent two Numbers, the smaller is assigned to a number, until the end of the array a is not the smallest number

CodePudding user response:

reference weixin_48192256 reply: 3/f
Quote: refer to the second floor qybao response:
because you just compare the adjacent two elements, non-adjacent than, so the result of natural right
Instead of
Min=a, [0].//min take the value of the first element
for (i=1; IIf (min> A [I])//and then each element with min than
Min=a, [I].
Printf (" % d ", min);
to start from scratch, each adjacent two Numbers, the smaller is assigned to a number, until the end of the array is a minimum number?
can also, like a bubble, then you should print a [I - 1] not print a [I], think about how much is the end of for loop I? I==n? The array length is n, the last element array subscript is how much?

CodePudding user response:

Upstairs, a [n] an array

CodePudding user response:

Qybao
reference 4 floor response:
Quote: refer to the third floor weixin_48192256 response:
Quote: refer to the second floor qybao response:
because you just compare the adjacent two elements, non-adjacent than, so the result of natural right
Instead of
Min=a, [0].//min take the value of the first element
for (i=1; IIf (min> A [I])//and then each element with min than
Min=a, [I].
Printf (" % d ", min);
to start from scratch, each adjacent two Numbers, the smaller is assigned to a number, until the end of the array is a minimum number?
can also, like a bubble, then you should print a [I - 1] not print a [I], think about how much is the end of for loop I? I==n? The array length is n, the last element array subscript is how much?
for loop inside the judgment of the conditions is not i CodePudding user response:

refer to 6th floor weixin_48192256 response:
Quote: refer to 4th floor qybao response:
Quote: refer to the third floor weixin_48192256 response:
Quote: refer to the second floor qybao response:
because you just compare the adjacent two elements, non-adjacent than, so the result of natural right
Instead of
Min=a, [0].//min take the value of the first element
for (i=1; IIf (min> A [I])//and then each element with min than
Min=a, [I].
Printf (" % d ", min);
to start from scratch, each adjacent two Numbers, the smaller is assigned to a number, until the end of the array is a minimum number?
can also, like a bubble, then you should print a [I - 1] not print a [I], think about how much is the end of for loop I? I==n? The array length is n, the last element array subscript is how much?
for loop inside the judgment of the conditions is not i


I=n - 1 when not out of the loop, perform i++ once again, this time I==n, just out of the loop

CodePudding user response:

refer to 7th floor WhiteCCai response:
Quote: refer to the sixth floor weixin_48192256 response:

Quote: refer to 4th floor qybao response:
Quote: refer to the third floor weixin_48192256 response:
Quote: refer to the second floor qybao response:
because you just compare the adjacent two elements, non-adjacent than, so the result of natural right
Instead of
Min=a, [0].//min take the value of the first element
for (i=1; IIf (min> A [I])//and then each element with min than
Min=a, [I].
Printf (" % d ", min);
to start from scratch, each adjacent two Numbers, the smaller is assigned to a number, until the end of the array is a minimum number?
can also, like a bubble, then you should print a [I - 1] not print a [I], think about how much is the end of for loop I? I==n? The array length is n, the last element array subscript is how much?
for loop inside the judgment of the conditions is not i


I=n - 1 when not out of the loop, perform i++ once again, this time I==n, just out of the loop

Oh oh oh, I see the
  • Related