# Untitled

unknown
c_cpp
a year ago
1.4 kB
1
Indexable
Never
```#include <iostream>
#include <cmath>

using namespace std;

double f(double x) {
return sin(pow(x, 2) - 5 * x) + 20 * log10(x);
}

double calculate_by_value(double a, double c) {
double ac = a * c;
double fa = f(a);
double fc = f(c);
double fac = f(ac);
double fac_div = f(a / c);

double result = (fa * fc - fac) / pow(fac_div, 2);

return result;
}

double calculate_by_reference(const double& a, const double& c) {
double ac = a * c;
double fa = f(a);
double fc = f(c);
double fac = f(ac);
double fac_div = f(a / c);

double result = (fa * fc - fac) / pow(fac_div, 2);

return result;
}

double calculate_by_pointer(const double* a, const double* c) {
double ac = (*a) * (*c);
double fa = f(*a);
double fc = f(*c);
double fac = f(ac);
double fac_div = f((*a) / (*c));

double result = (fa * fc - fac) / pow(fac_div, 2);

return result;
}

int main() {
double a = 5.6;
double c = 2;
double hc = 0.5;

while (c <= 7) {
double result1 = calculate_by_value(a, c);
double result2 = calculate_by_reference(a, c);
double result3 = calculate_by_pointer(&a, &c);
cout << "c=" << c << ", A=" << result1 << ", " << result2 << ", " << result3 << endl;
c += hc;
}

return 0;
}
```