C++ is implemented with a function with default parameters to find the largest number among 2 or 3 positive integers

1. The subject requirements are as follows:

C++ is implemented with a function with default parameters to find the largest number among 2 or 3 positive integers

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. The running results are as follows:

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/109012931