G
G
GoodOrlov2018-10-14 18:39:12
C++ / C#
GoodOrlov, 2018-10-14 18:39:12

Double Loop C++. Mathematical example. How to implement?

5bc3620f56400937603040.jpeg
One cycle is shorter than the other. How to be here?
y = ((a + 2 * x) / (sqrt(x))) - (pow(sqrt(4 * b), 1 / 3));
a = -18
Variable \ Initial value \(STEP)\Con. value
x = -1 (1) 10
b = 2 (2) 10

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2018-10-14
@GoodOrlov

#include <iostream>
#include <cmath>
using namespace std;

int fb(const int& b)
{
  return pow(4 * b, 1 / 3);
}

int fax(const int& a, const int& x)
{
  return (a + 2 * x) / pow(x, 1 / 2);
}

int main()
{
  const int a = -18;
  int resultAX = 0;
  int resultB = 0;

  for(int x = -1; x <= 10; ++x)
  {
    resultAX += fax(a, x);
  }

  for(int b = 2; b <= 10; b += 2)
  {
    resultB += fb(b);
  }

  cout << "x = " << resultAX << '\n'
       << "b = " << resultB << '\n'
       << "y = " << resultAX - resultB << endl;
}

OUT:
x = -108
b = 5
y = -113

Cm
double и int дают одинаковый результат.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question