用C语言编写程序:初始化一个5个元素的整数数组,数组的元素的值分别为5,7,9,12,15,用冒泡

2025-04-05 12:45:23
推荐回答(2个)
回答1:

#include

int main()
{
int num[] = {5,7,9,12,15};
int i,j,temp;

for (i = 0 ; i< 4 ;++i)
for (j = i+1 ;j <5 ;++j)
if (num[j] > num[i])
{
temp = num[j];
num[j] = num[i];
num[i] = temp;
}

for (i = 0 ;i<5;++i)
printf ("%d ",num[i]);
printf ("\n");

return 0;
}

回答2: