#include<stdio.h>
int main()
{
int a[7]={36,24,15,9,86,50,66},i,j;
printf("output the 7 numbers:\n");
for(i=0;i<7;i++)
printf("%d ",a[i]);
printf("\n");
int temp;
for(i=1; i<=7-1; i++)
{
for(j=1; j<=7-i; j++)
{
if(a[j-1] > a[j])
{
temp = a[j-1];
a[j-1] = a[j];
a[j] = temp;
}
}
}
printf("the sorted numbers:\n");
for(i=0;i<7;i++)
printf("%d ",a[i]);
return 0;
}
}
— 预期输出 —— -3 4 46 52 86 96 125
—— 实际输出 ——
output the 7 numbers:
the sorted numbers:
-3 4 46 52 86 96 125
for后接scanf("%d“,&a[i]);
会多出一个零,不知道为啥
如果没理解错你scanf添加的位置的话,是因为这里的这句会输出一个a[7],是没有赋值过的