首页 > 试题广场 >

使用重载函数编程序分别把两个数和三个数从大到小排列。

[问答题]

使用重载函数编程序分别把两个数和三个数从大到小排列。

推荐
#include<iostream>
using namespace std;
void sort( double x,double y );
void sort( double x,double y,double z );
int main()
{
sort( 5.6, 79 );
   sort( 0.5, 30.8, 5.9 );
}
void sort(double x,double y)
{
if ( x>y )
cout << x << '\t' << y << endl;
   else
 cout << y << '\t' << x << endl;
}

void sort( double x,double y,double z )

{

double t;

if( y<z ) { t = y; y = z; z = t; }

if( x<z ) { t = x; x = z; z = t; }

if( x<y ) { t = x; x = y ;y = t; }

cout << x << '\t' << y << '\t' << z << '\t' << endl;

}



发表于 2018-05-07 11:39:11 回复(0)