C/C++の宿題を片付けます 118代目
レス数が950を超えています。1000を超えると書き込みができなくなります。
0995デフォルトの名無しさん
2008/12/03(水) 22:13:32#include<stdio.h>
#include<stdlib.h>
#include<string.h>
float addition(int a, int b) {return (a + b);}
float subscription(int a, int b) {return (a - b);}
float multiplication(int a, int b) {return (a * b);}
float division(int a, int b) {return (a / b);}
float other(int a, int b) {return 0;}
float (*pfunc[])(int a, int b) = {other, addition,
subscription, multiplication,
division};
int main(){
int ope, a, b, f;
char *funcname[] = {"other", "addition", "subscription",
"multiplication", "division"};
printf("(1) addition\n(2) subscription\n(3) "
"multiplication\n(4) division\n上記以外 other\n\n");
while(1) {
printf("実行する演算の番号と2つの引数を入力して下さい : ");
f = scanf("%d %d %d", &ope, &a, &b);
if (f != 3) {
puts("入力おかしいです");
}
if (ope < 0 || 4 < ope )
ope = 0;
printf("%s(%d, %d) = %f\n\n\n", funcname[ope], a, b,
pfunc[ope](a, b));
}
return 0;
}
適当に脳内補完でお送りします
レス数が950を超えています。1000を超えると書き込みができなくなります。