提前批第二题:
#include <stdio.h>
#define N 10
void ReadData(int a[],int n);
void PrintData(int a[],int n);
void MaxMinExchange(int a[],int n);
void main(){
int a[N],n;
printf("Input n(n<=10):\n");
scanf("%d",&n);
if(n>0&&n<=10)
{
ReadData(a,n);
}
}
void ReadData(int a[],int n){
int i,Max,Min;
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
MaxMinExchange(a,n);
}
void MaxMinExchange(int a[],int n){
int Max,Min,i,b,c,temp;
for(Max=a[0],i=1;i<n;i++){
if(Max<a[i]){
Max=a[i];
}
}
for(Min=a[0],i=1;i<n;i++){
if(Min>a[i]){
Min=a[i];
}
}
for(b=0;b<n;b++){
if(a[b]==Max){
break;
}
}
for(c=0;c<n;c++){
if(a[c]==Min){
break;
}
}
temp=a[b];
a[b]=a[c];
a[c]=temp;
PrintData(a,n);
}
void PrintData(int a[],int n){
int i;
printf("Input %d numbers:",n);
printf("Exchange results:");
for(i=0;i<n;i++){
printf("%5d",a[i]);
if(i==n-1){
printf("\n");
}
}
}
标签:10,MaxMinExchange,int,na,void,笔记,C语言,学习,main
From: https://blog.csdn.net/2402_87160252/article/details/142931029