C/C++

Помогите С++ с цикла for нужно сделать while цикл и do while цикл точнее у меня вышла только с циклом for

#include
int main()
{
double a, n, d;
std::cout << "a = "; std::cin >> a;
std::cout << "n = "; std::cin >> n;
std::cout << "d = "; std::cin >> d;
if (d == 0.0)
{
std::cout << "Not defined !";
return 0;
}
else
{
double y = 1.0;
for (int j = 1; j <= 4; j++)
y *= j + 4;
y *= (n * n) / (d * d * d);
for (int i = 1; i <= 8; i++)
y += i + a;
std::cout << "y = " << y;
}
return 0;
}
#include <iostream>
using namespace std;
double real(const char* msg) {
cout << msg;
double value;
cin >> value;
cin.ignore(cin.rdbuf()->in_avail());
return value;
}
int main() {
const int x = 4;
const int h = 8;
auto a = real("a: ");
auto n = real("n: ");
auto d = 0.0;
while (!d) d = real("d: ");
auto m = 1.0;
int j = 0;
while (++j <= x) m *= n * n * (j + x);
auto t = m / pow(d, 3);
auto s = 0.0;
int i = 0;
while (++i <= h) s += i + a;
auto y = t + s;
cout << "y: " << y << '\n';
system("pause > nul");
}

#include <iostream>
using namespace std;
double real(const char* msg) {
cout << msg;
double value;
cin >> value;
cin.ignore(cin.rdbuf()->in_avail());
return value;
}
int main() {
const int x = 4;
const int h = 8;
auto a = real("a: ");
auto n = real("n: ");
double d;
do d = real("d: "); while (!d);
auto m = 1.0;
int j = 1;
do m *= n * n * (j + x); while (++j <= x);
auto t = m / pow(d, 3);
auto s = 0.0;
int i = 1;
do s += i + a; while (++i <= h);
auto y = t + s;
cout << "y: " << y << '\n';
system("pause > nul");
}

#include <iostream>
using namespace std;
double real(const char* msg) {
cout << msg;
double value;
cin >> value;
cin.ignore(cin.rdbuf()->in_avail());
return value;
}
int main() {
const int x = 4;
const int h = 8;
auto a = real("a: ");
auto n = real("n: ");
double d;
for (d = 0.0; !d; d = real("d: "));
auto m = 1.0;
for (int j = 1; j <= x; ++j) m *= n * n * (j + x);
auto t = m / pow(d, 3);
auto s = 0.0;
for (int i = 1; i <= h; ++i) s += i + a;
auto y = t + s;
cout << "y: " << y << '\n';
system("pause > nul");
}
Павел Калинин
Павел Калинин
59 042
Лучший ответ