C/C++の宿題片付けます 150代目
■ このスレッドは過去ログ倉庫に格納されています
0212デフォルトの名無しさん
2011/07/01(金) 00:07:07.64#include <stdio.h>
#include <string.h>
#include <math.h>
static char table[0x1000000][0x10];
#define NAME_LEN 16
#define BUF_LEN 256
double rad(double x) { return x / 180. * 3.14; }
double deq(double x) { return x / 3.14 * 180; }
struct {
char name[NAME_LEN];
double (*f)(double);
} functions[] = {{"sin", sin}, {"cos", cos}, {"arcsin", asin}, {"arctan", atan}, {"ln", log},
{"log", log10}, {"exp", exp}, {"sqr", sqrt}, {"rad", rad}, {"deq", deq},
{"sinh", sinh}, {"cosh", cosh}, {"tanh", tanh}};
int main()
{
char name[BUF_LEN];
double x;
int i;
while (scanf(" %[a-z]%lf", name, &x) == 2) {
printf("inst = %s(%f)\n", name, x);
for (i = 0; i < sizeof functions / sizeof functions[0]; i++)
if (!strcmp(functions[i].name, name))
printf("answer = %f\n", functions[i].f(x));
}
printf("なんか書式にあわないのを突っ込まれたので終了します");
return 0;
}
適当な部分があるので不満があるなら具体的に言ってもらえればなんとかします
■ このスレッドは過去ログ倉庫に格納されています