#include<stdio.h>
int main() {
int n;
printf("请输入数组元素个数:");
scanf_s("%d", &n);
int array[100]={0};
printf("请输入一组数:");
int i;
for ( i = 0; i < n; i++)
{
scanf_s("%d", &array[i]);
}
int min = array[0];
for ( i = 0; i < n; i++)
{
if (array[i]<min)
{
min = array[i];
}
}
printf("%d\n", min);
for ( i = 0; i < n; i++)
{
if (array[i]==min)
{
printf("%d\n", i);
break;
}
}
int temp = array[i];
array[i] = array[0];
array[0] = temp;
for (i = 0; i < n; i++)
{
printf("%5d", array[i]);
}
return 0;
}
/*从键盘输入n个数存放在数组中,将最小值与第一个数交换,输出交换后的n个数。*/
最新推荐文章于 2023-01-14 09:36:48 发布