/输入10个数,找出其中绝对值最小的数,将它和最后一个数交换,然后输出这10个数。/
#include <stdio.h>
int abs(int a)
{
return a >= 0 ? a : -a;
}
int main(void)
{
int nums[10];
int i, min_abs_index = 0;
printf("please enter ten number\n");
for (i = 0; i < 10; i++)
{
scanf("%d", &nums[i]);
}
for (i = 0; i < 10; i++)
{
if (abs(nums[i]) < abs(nums[min_abs_index]))
{
min_abs_index = i;
}
}
int temp = nums[min_abs_index];
nums[min_abs_index] = nums[9];
nums[9] = temp;
printf("交换后的数列为:\n");
for (i = 0; i < 10; i++)
{
printf("%d ", nums[i]);
}
printf("\n");
return 0;
}
标签:10,nums,int,index,min,个数,abs,绝对值
From: https://www.cnblogs.com/yesiming/p/18297358