calculator.c
This commit is contained in:
@@ -1,9 +1,32 @@
|
|||||||
#include "calculator.h"
|
#include "calculator.h"
|
||||||
|
|
||||||
|
int add(int a, int b){ return a + b;}
|
||||||
|
int sub(int a, int b){ return a - b;}
|
||||||
|
int mul(int a, int b){return a * b;}
|
||||||
|
int div(int a, int b){return a / b;}
|
||||||
|
int mod(int a, int b){return a % b;}
|
||||||
|
|
||||||
|
|
||||||
int calculator(int a, int b, enum operation op)
|
int calculator(int a, int b, enum operation op)
|
||||||
{
|
{
|
||||||
(void)a;
|
const operator lookup_table_name[] = {
|
||||||
(void)b;
|
|
||||||
(void)op;
|
[ADD] = &add,
|
||||||
return 0;
|
[SUB] = &sub,
|
||||||
|
[MUL] = &mul,
|
||||||
|
[DIV] = &div,
|
||||||
|
[MOD] = &mod,
|
||||||
|
};
|
||||||
|
|
||||||
|
return lookup_table_name[op](a, b);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
#include <stdio.h>
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int a = 144;
|
||||||
|
int b = 10;
|
||||||
|
enum operation op = MOD;
|
||||||
|
printf("calculator(%d, %d, %d) = %d\n", a, b, op, calculator(a, b, op));
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user