fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. double *dodaj(int a, int b)
  5. {
  6. double *c = new double;
  7. *c = a + b;
  8. return c;
  9. }
  10. double *odejmij(int a, int b)
  11. {
  12. double *c = new double;
  13. *c = a - b;
  14. return c;
  15. }
  16. double *pomnoz(int a, int b)
  17. {
  18. double *c = new double;
  19. *c = a * b;
  20. return c;
  21. }
  22. double *podziel(int a, int b)
  23. {
  24. double *c = new double;
  25. if (b != 0)
  26. *c = (double)a / b;
  27. else
  28. *c = 0;
  29. return c;
  30. }
  31.  
  32. int main()
  33. {
  34. double *(*g)(int, int);
  35. g = dodaj;
  36. cout << *g(2, 4) << endl;
  37. g = odejmij;
  38. cout << *g(2, 4) << endl;
  39. g = pomnoz;
  40. cout << *g(2, 4) << endl;
  41. g = podziel;
  42. cout << *g(2, 4) << endl;
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
6
-2
8
0.5