C++

[C++]명품 C++ 프로그래밍 실습문제 6장 3번

Hs’s Coding vlog 2023. 1. 10. 01:09

[C++]명품 C++ programming 실습문제 6장 3번

명품 C++ 프로그래밍실습문제/연습문제 /C++

//3-1
#include <iostream>
#include <string>
using namespace std;

int big(int a ,int b);
int big(int a, int b, int max);
int main(int argc, const char * argv[]) {
    
    int x =big(3,5);
    int y =big(300,60);
    int z =big(30,60,50);
    
    cout << x << ' ' << y << ' ' << z << endl;
    return 0;
}
int big(int a ,int b){
    int max = 100;
    if(a>b){
        if(max>a){
            return  a;
        }
        else
            return max;
    }
    else{
        if(max>b){
            return  b;
        }
        else
            return max;
        
    }

}
int big(int a ,int b,int max){//구현부에서 재구현을 할필요는 없다
    if(a>b){
        if(max>a){
            return  a;
        }
        else
            return max;
    }
    else{
        if(max>b){
            return  b;
        }
        else
            return max;
        
    }
 
}

//3-2

#include <iostream>
#include <string>
using namespace std;

int big(int a ,int b,int max=100);

int main(int argc, const char * argv[]) {
    
    int x =big(3,5);
    int y =big(300,60);
    int z =big(30,60,50);
    
    cout << x << ' ' << y << ' ' << z << endl;
    return 0;
}

int big(int a ,int b,int max){//구현부에서 재구현을 할필요는 없다
    if(a>b){
        if(max>a){
            return  a;
        }
        else
            return max;
    }
    else{
        if(max>b){
            return  b;
        }
        else
            return max;
        
    }
 
}