Home > Back-end >  Beginners CPP rookie for help
Beginners CPP rookie for help

Time:11-19

Topic is remove duplicate elements in the array, but what I write this cycle can output, saw several times didn't see that error, strives for the great god answer, thank you very much,

CodePudding user response:

The building before the last day for loop a print length is how much, if is 0, then no output is normal,
In the cycle of cover, I & lt; 9 this is problematic, because the total length may not be nine. Oh, so it should use the length, the other on the face length change in the while loop, so that the outer loop can also get the newest length

CodePudding user response:

Changes are as follows:
 int a [10], length=10; 
Cout<& lt;" Since the childhood, please input 10 integers: "& lt; for(int i=0; I<10; I++)
Cin> A, [I].

For (int t=0; t<9. T++)
If (a==[t] a [t + 1])
Length -;

for(int i=0; I<9. I++)
{
If (a==[I] a [I + 1))//the change
For (int j=I; j<9. J++)
A [j]=a, a + 1 bonus to [j].

}
for(int k=0; KCoutCoutreturn 0;
  • Related