-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpfunc.c
More file actions
33 lines (29 loc) · 742 Bytes
/
pfunc.c
File metadata and controls
33 lines (29 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.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; }
struct operations{
int (*ADD)(int a, int b);
int (*SUB)(int a, int b);
int (*MUL)(int a, int b);
int (*DIV)(int a, int b);
};
int main()
{
int a=8,b=2,result;
struct operations FUN;
FUN.ADD = add;
FUN.SUB = sub;
FUN.MUL = mul;
FUN.DIV = div;
result = FUN.ADD(a,b);
printf("result is %d\n\r",result);
result = FUN.SUB(a,b);
printf("result is %d\n\r",result);
result = FUN.MUL(a,b);
printf("result is %d\n\r",result);
result = FUN.DIV(a,b);
printf("result is %d\n\r",result);
return 0;
}