#include <iostream>
using namespace std;
double *dodaj(int a, int b)
{
double *c = new double;
*c = a + b;
return c;
}
double *odejmij(int a, int b)
{
double *c = new double;
*c = a - b;
return c;
}
double *pomnoz(int a, int b)
{
double *c = new double;
*c = a * b;
return c;
}
double *podziel(int a, int b)
{
double *c = new double;
if (b != 0)
*c = (double)a / b;
else
*c = 0;
return c;
}
int main()
{
double *(*g)(int, int);
g = dodaj;
cout << *g(2, 4) << endl;
g = odejmij;
cout << *g(2, 4) << endl;
g = pomnoz;
cout << *g(2, 4) << endl;
g = podziel;
cout << *g(2, 4) << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKZG91YmxlICpkb2RhaihpbnQgYSwgaW50IGIpCnsKICAgIGRvdWJsZSAqYyA9IG5ldyBkb3VibGU7CiAgICAqYyA9IGEgKyBiOwogICAgcmV0dXJuIGM7Cn0KZG91YmxlICpvZGVqbWlqKGludCBhLCBpbnQgYikKewogICAgZG91YmxlICpjID0gbmV3IGRvdWJsZTsKICAgICpjID0gYSAtIGI7CiAgICByZXR1cm4gYzsKfQpkb3VibGUgKnBvbW5veihpbnQgYSwgaW50IGIpCnsKICAgIGRvdWJsZSAqYyA9IG5ldyBkb3VibGU7CiAgICAqYyA9IGEgKiBiOwogICAgcmV0dXJuIGM7Cn0KZG91YmxlICpwb2R6aWVsKGludCBhLCBpbnQgYikKewogICAgZG91YmxlICpjID0gbmV3IGRvdWJsZTsKICAgIGlmIChiICE9IDApCiAgICAgICAgKmMgPSAoZG91YmxlKWEgLyBiOwogICAgZWxzZQogICAgICAgICpjID0gMDsKICAgIHJldHVybiBjOwp9CgppbnQgbWFpbigpCnsKCWRvdWJsZSAqKCpnKShpbnQsIGludCk7CglnID0gZG9kYWo7Cgljb3V0IDw8ICpnKDIsIDQpIDw8IGVuZGw7CglnID0gb2Rlam1pajsKCWNvdXQgPDwgKmcoMiwgNCkgPDwgZW5kbDsKCWcgPSBwb21ub3o7Cgljb3V0IDw8ICpnKDIsIDQpIDw8IGVuZGw7CglnID0gcG9kemllbDsKCWNvdXQgPDwgKmcoMiwgNCkgPDwgZW5kbDsKCQoJcmV0dXJuIDA7Cn0=