Insert a number into the sorted array and arrange the order

Viewed 47

I have written a C language program, but the result is not satisfactory. The output result is:

0  20  22  23  24  25  26   0   0   0

Code show as below

int a[10] = {20, 22, 23, 24, 25, 26}, i, t, n;
for(i=6, a[6] == 21; a[i] <a[i-1] && i > 0; i--)
{
    t = a[i];
    a[i] = a[i-1];
    a[i-1] = t;
}
for(n = 0; n < 10; n++)
    printf("%4d",a[n]);
printf("\n");
return 0;
0 Answers
Related