
输入n(n≤20)个数放在一维数组中,找出其中最小的数,将它与数组最前面的数交换后输出这些数。
C语言输入n(n≤20)个数放在一维数组中,找出其中最小的数,将它与数组最前面的数交换后输出这些数。...
C语言
输入n(n≤20)个数放在一维数组中,找出其中最小的数,将它与数组最前面的数交换后输出这些数。 展开
输入n(n≤20)个数放在一维数组中,找出其中最小的数,将它与数组最前面的数交换后输出这些数。 展开
展开全部
#include<stdio.h>
#define A 20 /*定义常数*/
main()
{
int ary[A];
int i=0,j=0,m;
int SIZE;
printf("Please input the size of the array:");
scanf("%d",&SIZE);
for(i=0;i<SIZE;i++)
{
printf("Please input number %d:",i+1);
scanf("%d",&ary[i]);
}
m=finds(ary,SIZE);/*返回最小数在数组中的下标*/
swap(m,ary);/*交换*/
for(j=0;j<SIZE;j++)
{
printf("The array %d is %d\n",j+1,ary[j]);/*输出交换后的结果*/
}
getch();
}
int finds(int b[A],int SIZE)
{
int m=0;
int k=0;
int temp;
temp=b[0];
for(m=1;m<SIZE;m++)
{
if(b[m]<temp)
{
temp=b[m];
k=m;
}
else
continue;
}
return k;
}
void swap(int c,int d[A])
{
int temp=0;
temp=d[0];
d[0]=d[c];
d[c]=temp;
}
#define A 20 /*定义常数*/
main()
{
int ary[A];
int i=0,j=0,m;
int SIZE;
printf("Please input the size of the array:");
scanf("%d",&SIZE);
for(i=0;i<SIZE;i++)
{
printf("Please input number %d:",i+1);
scanf("%d",&ary[i]);
}
m=finds(ary,SIZE);/*返回最小数在数组中的下标*/
swap(m,ary);/*交换*/
for(j=0;j<SIZE;j++)
{
printf("The array %d is %d\n",j+1,ary[j]);/*输出交换后的结果*/
}
getch();
}
int finds(int b[A],int SIZE)
{
int m=0;
int k=0;
int temp;
temp=b[0];
for(m=1;m<SIZE;m++)
{
if(b[m]<temp)
{
temp=b[m];
k=m;
}
else
continue;
}
return k;
}
void swap(int c,int d[A])
{
int temp=0;
temp=d[0];
d[0]=d[c];
d[c]=temp;
}
展开全部
#include<stdio.h>
#define A 20 /*定义常数*/
main()
{
int ary[A];
int i=0,j=0,m;
int SIZE;
printf("Please input the size of the array:");
scanf("%d",&SIZE);
for(i=0;i<SIZE;i++)
{
printf("Please input number %d:",i+1);
scanf("%d",&ary[i]);
}
m=finds(ary,SIZE);/*返回最小数在数组中的下标*/
swap(m,ary);/*交换*/
for(j=0;j<SIZE;j++)
{
printf("The array %d is %d\n",j+1,ary[j]);/*输出交换后的结果*/
}
getch();
}
int finds(int b[A],int SIZE)
{
int m=0;
int k=0;
int temp;
temp=b[0];
for(m=1;m<SIZE;m++)
{
if(b[m]<temp)
{
temp=b[m];
k=m;
}
else
continue;
}
return k;
}
void swap(int c,int d[A])
{
int temp=0;
temp=d[0];
d[0]=d[c];
d[c]=temp;
}
#define A 20 /*定义常数*/
main()
{
int ary[A];
int i=0,j=0,m;
int SIZE;
printf("Please input the size of the array:");
scanf("%d",&SIZE);
for(i=0;i<SIZE;i++)
{
printf("Please input number %d:",i+1);
scanf("%d",&ary[i]);
}
m=finds(ary,SIZE);/*返回最小数在数组中的下标*/
swap(m,ary);/*交换*/
for(j=0;j<SIZE;j++)
{
printf("The array %d is %d\n",j+1,ary[j]);/*输出交换后的结果*/
}
getch();
}
int finds(int b[A],int SIZE)
{
int m=0;
int k=0;
int temp;
temp=b[0];
for(m=1;m<SIZE;m++)
{
if(b[m]<temp)
{
temp=b[m];
k=m;
}
else
continue;
}
return k;
}
void swap(int c,int d[A])
{
int temp=0;
temp=d[0];
d[0]=d[c];
d[c]=temp;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
main()
{int i,tem,min;
int aa[20];
for(i=0;i<20;i++)
scanf("%d",aa+i);
tem=aa[0];
for(i=1;i<20;i++)
if(tem>aa[i]){tem=aa[i];min=i; }
tem=aa[0];aa[0]=aa[min];aa[min]=tem;
for(i=0;i<20;i++)
printf("%d\t",aa[i]);
}
{int i,tem,min;
int aa[20];
for(i=0;i<20;i++)
scanf("%d",aa+i);
tem=aa[0];
for(i=1;i<20;i++)
if(tem>aa[i]){tem=aa[i];min=i; }
tem=aa[0];aa[0]=aa[min];aa[min]=tem;
for(i=0;i<20;i++)
printf("%d\t",aa[i]);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询