C语言考试练习题_最值
来源:百度知道 编辑:UC知道 时间:2024/06/19 05:46:19
Description
有一个长度为n的整数序列。请写一个程序,把序列中的最小值与第一个数交换,最大值与最后一个数交换。输出转换好的序列。
Input
输入包括两行。
第一行为正整数n(1≤n≤10)。
第二行为n个正整数组成的序列。
Output
输出转换好的序列。数据之间用空格隔开。
Sample Input
5
2 1 5 4 3
Sample Output
1 2 3 4 5
谁能给个简单点的程序啊
有一个长度为n的整数序列。请写一个程序,把序列中的最小值与第一个数交换,最大值与最后一个数交换。输出转换好的序列。
Input
输入包括两行。
第一行为正整数n(1≤n≤10)。
第二行为n个正整数组成的序列。
Output
输出转换好的序列。数据之间用空格隔开。
Sample Input
5
2 1 5 4 3
Sample Output
1 2 3 4 5
谁能给个简单点的程序啊
#include "stdio.h"
change(int a[],int n)
{
int p,i,temp;
temp=a[0];
p=0;
for(i=0;i<n;i++) /*最小数与第一个交换*/
{
if(temp>a[i])
{
temp=a[i];
p=i;
}
}
a[p]=a[0];
a[0]=temp;
for(i=0;i<n;i++) /*最大数与最后一个交换*/
{
if(temp<a[i])
{
temp=a[i];
p=i;
}
}
a[p]=a[n-1];
a[n-1]=temp;
}
print(int a[],int n) /*打印数组*/
{
int i;
for(i=0;i<n;i++)
{
printf("%d ",a[i]) ;
}
}
main()
{
int n,i,a[50];
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
change(a,n);
print(a,n);
getch();
}
我哥说他学过,可是忘了
#include <stdio.h>
int main()
{
int i,j,k=0,n,m=0,max,min,a[12];
sc