написал на с++
Объяснение:
#include <iostream>
#include <windows.h>//для русской раскладки
using namespace std;
int main()
{
SetConsoleCP(1251);//подключаем русскую раскладку
SetConsoleOutputCP(1251);
float a[3][4]; //двумерный массив
cout << "Введите элементы массива:" << endl;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
cout << "a[" << i + 1 << "][" << j + 1 << "]= ";
cin >> a[i][j];
}
}
cout << "Введенная матрица до изменения:" << endl; //вывод матрицы B
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
cout.width(7);// выравниваем числа по7 позиций
cout << a[i][j];
}
cout << endl;
}
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
if (a[i][j] == 0)
a[i][j] = 10;
}
}
cout << "Введенная матрица после изменения:" << endl; //вывод матрицы B
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
cout.width(7);// выравниваем числа по7 позиций
cout << a[i][j];
}
cout << endl;
}
system("pause");
return 0;
}
Файл с фамилиями и ростом прикреплён.
#include <iostream>
#include <fstream>
#include <windows.h>
using namespace std;
class People {
public:
string surname;
int height;
};
signed main() {
ifstream f;
People ppl[15];
int j = 0;
People newPpl;
try {
cout << "Input surname and height new people:\n";
cin >> newPpl.surname >> newPpl.height;
try {
f.open("guys.txt");
while (!f.eof()) {
f >> ppl[j].surname >> ppl[j].height;
j++;
}
}
catch (...) {
cout << "Error with file!";
}
int _minR = abs(newPpl.height - ppl[0].height);
string buff = ppl[0].surname;
for (int i = 0; i < 15; i++) {
if (abs(newPpl.height - ppl[i].height) < _minR) {
_minR = abs(newPpl.height - ppl[i].height);
buff = ppl[i].surname;
}
}
cout << endl << buff;
}
catch (...) {
cout << "Error in main programm!";
}
return 0;
}