Даны два действительных числа X и Y, не равные друг другу. Заменить меньшее из этих чисел половиной их суммы, а большее – их удвоенным произведением. желательно сделайте в таблице.
Напишите пожалуйста код на C++
Другие языки программирования и технологии
Напишите код на C++
std::tie(X < Y? X : Y, X < Y? Y : X) = std::make_pair((X+Y)/2.,X*Y*2.);
#include "iostream"
using namespace std;
int main(){
double a,b,c,d; cout<<"a b: "; cin>>a>>b;
c=2*a*b; d=(a+b)/2; if(a>b)a=c,b=d; else b=c,a=d;
cout<<"a="<<a<<", b="<<b<<endl;}
using namespace std;
int main(){
double a,b,c,d; cout<<"a b: "; cin>>a>>b;
c=2*a*b; d=(a+b)/2; if(a>b)a=c,b=d; else b=c,a=d;
cout<<"a="<<a<<", b="<<b<<endl;}
int main() {
/*SetConsoleCP(866);
SetConsoleOutputCP(866);*/
//auto now = chrono::high_resolution_clock::now();
//auto Random(now.time_since_epoch().count());
double x, y;
cout << "x = " << flush;
cin >> x;
cout << "y = " << flush;
cin >> y;
cout << "--------------------------------------------\n\n" << flush;
cin.get();
if (x == y) return -1;
if (x < y) {
double temp = x;
x = (x + y) / 2;
y = temp * y * 2;
}
else {
double temp = y;
y = (x + y) / 2;
x = temp * y * 2;
}
for (int i(0); i < 9; ++i) {
if (!i) {
cout << char(218);
for (int j(1); j < 29; ++j) {
if (j == 29 / 2) {
cout << char(194);
}
else {
cout << char(196);
}
}
cout << char(191) << endl;
}
else if (i == 4) {
cout << char(195);
for (int j(1); j < 29; ++j) {
if (j == 29 / 2) {
cout << char(197);
}
else {
cout << char(196);
}
}
cout << char(180) << endl;
}
else if (i == 8) {
cout << char(192);
for (int j(1); j < 29; ++j) {
if (j == 29 / 2) {
cout << char(193);
}
else {
cout << char(196);
}
}
cout << char(217) << endl;
}
else {
cout << char(179);
for (int j(1); j < 29 ; ++j) {
if (j == 29 / 2) {
cout << char(179);
}
else {
if (j == 29 / 4) {
if (i == 2) {
cout << "x"; ++j;
}
if (i == 6) {
cout << "y"; ++j;
}
}
if (j == 29 / 2 + 29 / 4) {
if (i == 2) {
cout << fixed << setprecision(2) << x;
int temp = x;
int counter = 0;
while (temp) {
temp /= 10;
++counter;
}
j += counter + 3;
}
if (i == 6) {
cout << fixed << setprecision(2) << y;
int temp = y;
int counter = 0;
while (temp) {
temp /= 10;
++counter;
}
j += counter + 3;
}
}
cout << " ";
}
}
cout << char(179) << endl;
}
}
cin.get();
return 0;
}
/*SetConsoleCP(866);
SetConsoleOutputCP(866);*/
//auto now = chrono::high_resolution_clock::now();
//auto Random(now.time_since_epoch().count());
double x, y;
cout << "x = " << flush;
cin >> x;
cout << "y = " << flush;
cin >> y;
cout << "--------------------------------------------\n\n" << flush;
cin.get();
if (x == y) return -1;
if (x < y) {
double temp = x;
x = (x + y) / 2;
y = temp * y * 2;
}
else {
double temp = y;
y = (x + y) / 2;
x = temp * y * 2;
}
for (int i(0); i < 9; ++i) {
if (!i) {
cout << char(218);
for (int j(1); j < 29; ++j) {
if (j == 29 / 2) {
cout << char(194);
}
else {
cout << char(196);
}
}
cout << char(191) << endl;
}
else if (i == 4) {
cout << char(195);
for (int j(1); j < 29; ++j) {
if (j == 29 / 2) {
cout << char(197);
}
else {
cout << char(196);
}
}
cout << char(180) << endl;
}
else if (i == 8) {
cout << char(192);
for (int j(1); j < 29; ++j) {
if (j == 29 / 2) {
cout << char(193);
}
else {
cout << char(196);
}
}
cout << char(217) << endl;
}
else {
cout << char(179);
for (int j(1); j < 29 ; ++j) {
if (j == 29 / 2) {
cout << char(179);
}
else {
if (j == 29 / 4) {
if (i == 2) {
cout << "x"; ++j;
}
if (i == 6) {
cout << "y"; ++j;
}
}
if (j == 29 / 2 + 29 / 4) {
if (i == 2) {
cout << fixed << setprecision(2) << x;
int temp = x;
int counter = 0;
while (temp) {
temp /= 10;
++counter;
}
j += counter + 3;
}
if (i == 6) {
cout << fixed << setprecision(2) << y;
int temp = y;
int counter = 0;
while (temp) {
temp /= 10;
++counter;
}
j += counter + 3;
}
}
cout << " ";
}
}
cout << char(179) << endl;
}
}
cin.get();
return 0;
}
Похожие вопросы
- Помогите написать код на C++
- Помогите написать код на C++
- Помогите написать код на C++
- Как правилоно написать код по C++
- Написать код на C++.по задаче.
- Написал калькулятор на c++ он не работает вот код
- Исправление кода на C++
- Помогите откорректировать код в C++
- Описать код на C# с помощью госта 1981 года.
- !!! Каким кодом на C++ можно реализовать следующую задачу? помогите написать программку !!!