1.题目如下:

C++用函数重载实现两个整数和三个浮点数的排序,按照从小到大的顺序将排序结果输出

2.来吧,展示:

#include <iostream>
using namespace std;

void sort(int a,int b)
{
    int temp;
    if (a>b){temp = a;a = b;b = temp;}
    cout <<a<< ',' <<b<<endl;
}

void sort(float x,float y,float z)
{
    float temp;
    if(x>y){temp=x;x=y;y=temp;}
    if(z<x) cout <<z<< ',' <<x<< ',' <<y<< endl;
        else if(z<y) cout <<x<< ',' <<z<< ',' <<y<< endl;
            else cout <<x<< ',' <<y<< ',' <<z<< endl;
}

int main()
{
    void sort(int a,int b);
    void sort(float x,float y,float z);
    float x,y,z;
    int a,b;
    cout <<"请输入两个整数:"<<endl;
    cin >>a>>b;
    cout << "排序从小到大为:" << endl;
    sort(a,b);
    cout <<"请输入三个浮点数:"<<endl;
    cin >>x>>y>>z;
    cout << "排序从小到大为:" << endl;
    sort(x,y,z);
    return 0;
}

3.运行结果:

C++用函数重载实现两个整数和三个浮点数的排序,按照从小到大的顺序将排序结果输出

 

 

希望能帮到大家,问你们要一个赞,你们会给吗,谢谢大家
版权声明:本文版权归作者(@攻城狮小关)和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
大家写文都不容易,请尊重劳动成果~
交流加Q:1909561302
CSDN地址https://blog.csdn.net/Mumaren6/

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-20
  • 2021-06-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2018-08-07
相关资源
相似解决方案