9.自定義函數

#include <bits/stdc++.h>
using namespace std;
/*
    自定義函數
    回傳型別 函數名稱(傳入值){
        return -> 回傳
        * void 代表 空 所以不用return
     }
*/
int add(int a , int b){
    return a + b;
}
int sub(int a , int b){
    return a - b;
}
void print(int a , int b){
    cout << a << " " << b << endl;
}
int main(){
    int a , b , x , y;
    /*
        這裡的 a , b
        跟 自定義函數裡的 a , b 不同
        也不互相衝突
    */
    cin >> a >> b;
    x = add(a , b);
    y = sub(a , b);
    print(x , y);
    return 0;
}

results matching ""

    No results matching ""