fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <functional>
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. int mul(int x, int y){
  8.  
  9. return x*y;
  10. }
  11. int dif(int x, int y){
  12.  
  13. return x/y;
  14. }
  15. int sum(int x, int y){
  16.  
  17. return x+y;
  18. }
  19. int sub(int x, int y){
  20.  
  21. return x-y;
  22. }
  23.  
  24.  
  25. int main() {
  26. int x, y;
  27. x = 5;
  28. y = 2;
  29. int(*funPtr1)(int, int) = mul;
  30. int(*funPtr2)(int, int) = sum;
  31. //z2
  32. int(*tabFunPtr[4]) (int x, int y);
  33. tabFunPtr[0] = mul;
  34. tabFunPtr[1] = dif;
  35. tabFunPtr[2] = sum;
  36. tabFunPtr[3] = sub;
  37. //z4
  38. auto lamMul = [&](int x, int y) -> int{
  39. return x*y;
  40. };
  41. auto lamDif = [&](int x, int y) -> int{
  42. return x / y;
  43. };
  44. auto lamSum = [&](int x, int y) -> int{
  45. return x + y;
  46. };
  47. auto lamSub = [&](int x, int y) -> int{
  48. return x - y;
  49. };
  50.  
  51.  
  52.  
  53. cout << mul(x,y) << endl;
  54. cout << dif(x,y) << endl;
  55. cout << sum(x,y) << endl;
  56. cout << sub(x,y) << endl;
  57. cout <<"------------------------"<<endl;
  58. cout << funPtr1(x,y)<<endl;
  59. cout << funPtr2(x,y)<<endl;
  60. cout <<"-------------z2---------"<< endl;
  61. for(int i =0; i<4; i++){
  62. cout << (*tabFunPtr[i])(x, y) << endl;
  63. }
  64. cout << "------------------------z3--------"<< endl;
  65. cout << lamMul(x, y) << endl;
  66. cout << lamDif(x, y) << endl;
  67. cout << lamSum(x, y) << endl;
  68. cout << lamSub(x, y) << endl;
  69.  
  70.  
  71. system("pause");
  72. return 0;
  73. }
Success #stdin #stdout #stderr 0s 3140KB
stdin
Standard input is empty
stdout
10
2
7
3
------------------------
10
7
-------------z2---------
10
2
7
3
------------------------z3--------
10
2
7
3
stderr
sh: 1: pause: not found