forked from piyush01123/Daily-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sol.cpp
46 lines (36 loc) · 733 Bytes
/
sol.cpp
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
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
int addition(int x, int y){
return x+y;
}
int subtraction(int x, int y){
return x-y;
}
// int cons(int a, int b, int (*func)(int, int)){
// int res = (*func)(a, b);
// return res;
// }
//
// int car(){
//
// }
int pair(int a, int b, int (*f)(int, int)){
int res = (*f)(a, b);
return res;
}
int (*cons(int, int))(int a, int b){
int (*f)(int, int);
return f;
}
struct pair_{
int a, b;
int (*f)(int, int);
};
int main(){
pair_ p1 = {5, 10, addition};
pair_ p2 = {5, 10, subtraction};
int a = (p1.f(p1.a, p1.b) + p2.f(p2.a, p2.b))/2;
int b = (p1.f(p1.a, p1.b) - p2.f(p2.a, p2.b))/2;
std::cout<<a<<' '<<b<<'\n';
// int sum = cons(5, 6, addition);
// std::cout<<sum<<'\n';
}