#include <stdio.h>
#define PLUS 1 // メソッドとして使うためにマクロを定義する
#define MINUS 2 // 上に同じ。こちらは引き算のメソッドで、上のが足し算メソッド
int object (int method,int valuea,int valueb);
int main(int argc, const char * argv[])
{
int valuea = 0; //数値A
int valueb = 0; //数値B
int command = 0; //コマンド
int anser = 0; //答え
scanf("%d",&valuea
); //数値Aに代入 scanf("%d",&valueb
); //数値Bに代入 printf("\n実行する計算のコマンドを入力してね\n"); scanf("%d",&command
); //変数commandに代入
if (command == 1) anser = object(PLUS, valuea,valueb);//コマンドが1ならばobject関数に足し算をするようにメソッドを送る
else if (command == 2) anser = object(MINUS, valuea, valueb);//コマンドが2ならばobject関数に引き算をするようにメソッドを送る
//object関数から帰ってきた計算の答えを変数anserに代入する
printf("\n答えは%dになりましたとさ。",anser
); //答えが入っている変数anserを標準出力
return 0;
}
int object (int method,int valuea,int valueb){
int anser = 0; //答えを格納する変数anser
switch (method) {
//変数methodにより処理を変える
case PLUS: //もしmethodがマクロPLUS(1)なら
anser = valuea + valueb; //数値AとBを足して変数anserに代入
break;
case MINUS: //もしmethodがマクロMINUS(2)なら
anser = valuea - valueb; //数値AからBを引いて変数anserに代入
default:
break;
}
return anser; //計算の答えが格納されている変数anserを返す
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgojZGVmaW5lIFBMVVMgMSAvLyDjg6Hjgr3jg4Pjg4njgajjgZfjgabkvb/jgYbjgZ/jgoHjgavjg57jgq/jg63jgpLlrprnvqnjgZnjgosKI2RlZmluZSBNSU5VUyAyIC8vIOS4iuOBq+WQjOOBmOOAguOBk+OBoeOCieOBr+W8leOBjeeul+OBruODoeOCveODg+ODieOBp+OAgeS4iuOBruOBjOi2s+OBl+eul+ODoeOCveODg+ODiQoKaW50IG9iamVjdCAoaW50IG1ldGhvZCxpbnQgdmFsdWVhLGludCB2YWx1ZWIpOwoKaW50IG1haW4oaW50IGFyZ2MsIGNvbnN0IGNoYXIgKiBhcmd2W10pCnsKICAgIGludCB2YWx1ZWEg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cuOBq+S7o+WFpeOBmeOCiwogICAgCiAgICBwcmludGYoIlxu562U44GI44GvJWTjgavjgarjgorjgb7jgZfjgZ/jgajjgZXjgIIiLGFuc2VyKTsgLy/nrZTjgYjjgYzlhaXjgaPjgabjgYTjgovlpInmlbBhbnNlcuOCkuaomea6luWHuuWKmwogICAgCiAgICByZXR1cm4gMDsKfQoKaW50IG9iamVjdCAoaW50IG1ldGhvZCxpbnQgdmFsdWVhLGludCB2YWx1ZWIpewogICAgCiAgICBpbnQgYW5zZXIgPSAwOyAvL+etlOOBiOOCkuagvOe0jeOBmeOCi+WkieaVsGFuc2VyCiAgICAKICAgIHN3aXRjaCAobWV0aG9kKSB7CiAgICAgICAgICAgIC8v5aSJ5pWwbWV0aG9k44Gr44KI44KK5Yem55CG44KS5aSJ44GI44KLCiAgICAgICAgY2FzZSBQTFVTOiAvL+OCguOBl21ldGhvZOOBjOODnuOCr+ODrVBMVVMo77yRKeOBquOCiQogICAgICAgICAgICBhbnNlciA9IHZhbHVlYSArIHZhbHVlYjsgLy/mlbDlgKRB44GoQuOCkui2s+OBl+OBpuWkieaVsGFuc2Vy44Gr5Luj5YWlCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGNhc2UgTUlOVVM6IC8v44KC44GXbWV0aG9k44GM44Oe44Kv44OtTUlOVVMoMinjgarjgokKICAgICAgICAgICAgYW5zZXIgPSB2YWx1ZWEgLSB2YWx1ZWI7IC8v5pWw5YCkQeOBi+OCiULjgpLlvJXjgYTjgablpInmlbBhbnNlcuOBq+S7o+WFpQogICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIHByaW50ZigiXG7jgYjjgonjg7xcbiIpOyAvL+OBiOOCieODvOWHpueQhgogICAgICAgICAgICBicmVhazsKICAgIH0KICAgIAogICAgcmV0dXJuIGFuc2VyOyAvL+ioiOeul+OBruetlOOBiOOBjOagvOe0jeOBleOCjOOBpuOBhOOCi+WkieaVsGFuc2Vy44KS6L+U44GZCn0=