c + +Save the children!
# include & lt; stdio.h>
# include & lt; stdlib.h>
#include
20 # define N
Int main ()
{int score [N], I, a, t, k, b, x, c=0; Srand (time (NULL)); for(i=0; i<19. I++) {score [I]=rand () 100 + % 1; } the for (I=0; i<19. I++) {k=I; For (a=I + 1; A<19. {+) if (score [k] & gt; Score [a]) {k=a; } the if (k! I)={t=score [k]. Score=score [k] [I]; Score [I]=t; }} printf (" % d ", score [I]); } printf (" \ n "); Printf (" input x: "); The scanf (" % d ", & amp; X); While (x> [c]=score & amp; & c<20) {c + +; } b=c; For (c=19; C>=b; C -) {score=[c + 1] score [c]; [b]} score=x; printf("\n"); for(i=0; i<20; I++) {printf (" % d ", score [I]); } return 0;
}
CodePudding user response:
# include & lt; stdio.h>
# include & lt; stdlib.h>
#include
20 # define N
Int main ()
{
Int score [N], I, a, t, k, b, x, c=0;
Srand (time (NULL));
//for (I=0; i<19. I++) {
for(i=0; iScore [I]=rand () % 100 + 1;
}
for(i=0; iK=I;
For (a=I + 1; AIf (score [k] & gt; Score [a]) {
K=a;
}
if(k! I)={
T=score [k].
Score=score [k] [I];
Score [I]=t;
}
}
Printf (" % d ", score [I]);
}
printf("\n");
Printf (" input x: ");
The scanf (" % d ", & amp; X);
While (x & gt; [c]=score & amp; & C & lt; N) {
C + +;
}
B=c.
//for (c=19; C>=b; C -) {//c=19, c + 1 had already crossed the
For (c=N - 2; C & gt;=b; C -) {
Score=[c + 1] score [c];
}
Score [b]=x;
printf("\n");
//for (I=0; i<20; I++) {
for(i=0; iPrintf (" % d ", score [I]);
}
return 0;
}
For your reference ~
CodePudding user response:
The