题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2016
题目大意:把最小的和第一个交换并输出。注意格式哦!
1 #include <stdio.h> 2 int main () 3 { 4 int n,a[110],i,j,t,min; 5 while (scanf("%d",&n)!=EOF) 6 { 7 if (n==0) 8 break; 9 for (i=0; i<n; i++) 10 { 11 scanf("%d",&a[i]); 12 } 13 min=a[0]; 14 j=0; 15 for (i=1; i<n; i++) 16 if (min>a[i])//找到最小值 17 { 18 min=a[i]; 19 j=i; 20 } 21 t=a[j]; 22 a[j]=a[0]; 23 a[0]=t; 24 for (i=0; i<n-1; i++) 25 printf ("%d ",a[i]); 26 printf ("%d\n",a[i]); 27 } 28 return 0; 29 }