C++ uses function overloading to realize the sorting of two integers and three floating-point numbers, and output the sorting results in ascending order

1. The topic is as follows:

C++ uses function overloading to realize the sorting of two integers and three floating-point numbers, and output the sorting results in ascending order

2. Come on, show:

#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. Operation results:

I hope I can help everyone, I ask you if you want a like, will you give it, thank you all.
Copyright statement: The copyright of this article belongs to the author (@攻城狮小关) and CSDN. Welcome to reprint, but you must keep this paragraph without the author’s consent Statement, and provide the original link in an obvious place on the article page, otherwise the right to pursue legal responsibility is reserved.
It is not easy for everyone to write articles, please respect the fruits of labor~ 
Communication plus Q: 1909561302
Blog Park Address https://www.cnblogs.com/guanguan-com/

 

Guess you like

Origin blog.csdn.net/Mumaren6/article/details/109013521