用C语言将9个不同大小的数字按从大到小排列

来源:百度知道 编辑:UC知道 时间:2024/06/18 10:39:38
用c的库函数,头文件用<stdio.h>的或是最好有指针 函数 或是数组

#include<iostream>
using namespace std;

void input (int[] ,int);
void getHighest(int[],int,int&);

const int NUM=9;
int main()
{
int Num[NUM];
int max;
int m;

input(Num,NUM);
for(m=0;m<NUM;m++)
{
getHighest(Num,NUM,max);
cout<<max<<endl;

}

return 0;
}

void input( int Num[], int n)
{
int m;

cout<<"Please enter "<<n<<" numbers."<<endl;
for(m=0;m<n;m++)
{
cout<<"Enter the number("<<m+1<<"): ";
cin>>Num[m];
}
}

void getHighest (int Num[], int n, int&max)
{
int m;
max=Num[0];
for(m=0;m<n;m++)
{
if(Num[m]>max)
{
int temp;
temp=max;
max=Num[m];
Num[m]=temp;
}

}