Вы находитесь на странице: 1из 3

Практическое занятие 3

Задание 1. №8

#include <iostream>
#include <ctime>
using namespace std;
int main()
{ setlocale(LC_ALL, "Russian");
srand(time(0));
const int N = 16;
double mass[N];
cout << "Массив = {";
for (int i = 0; i < N; i++)
{ mass[i] = rand() % 101;
cout << mass[i];
if (i - (N - 1) != 0) {
cout << ", ";
}
} cout << "}" << endl;
cout << endl;

int imax = 0;
int max = mass[0];
for (int i = 1; i < N; i++)
{ if (mass[i] > max)
{
max = mass[i];
imax = i;
}
}
cout << "Максимальное значение = " << max << "\n" << "Индекс максимального
значения = " << imax << endl;
cout << endl;
int min = mass[0];
int imin = 0;
for (int i = 1; i < N; i++)
{ if (mass[i] < min)
{ min = mass[i];
imin = i;
}
}
cout << "Минимальное значение = " << min << "\n" << "Индекс минимального значения
= " << imin << endl;
system("pause");
}
Задание 2. №13

#include <iostream>
#include <ctime>
#include <iomanip>
using namespace std;
int main()
{ setlocale(LC_ALL, "Russian");
srand(time(0));
int i, j;
int mass[6][6];
int smass[6];
cout << "Генерируем массив: " << endl;
cout << endl;
for (i = 0; i < 6; i++)
{ cout << "|";
for (j = 0; j < 6; j++)
{ mass[i][j] = -100 + rand() % 201;
if (j < 5)
cout << mass[i][j] << "," << setw(6);
else
cout << mass[i][j] << "|" << endl;
}
}
cout << endl;
cout << endl;
cout << "Считаем сумму первой и последней строки:" << endl;
cout << endl;
i = 0;
for (j = 0; j < 6; j++) {
smass[i] = mass[0][j] + mass[5][j];
i++;
}
i = 0;
for (j = 0; j < 6; j++) {
cout << mass[0][j] << " + " << mass[5][j] << " = " << smass[i] << endl;
i++;
}
cout << endl;
cout << endl;
cout << "Массив с суммой, вписанной в первый столбец: " << endl;
cout << endl;
for (i = 0; i < 6; i++) {
cout << "|";
cout << smass[i] << "," << setw(6);
for (j = 1; j < 6; j++) {
if (j < 5)
cout << mass[i][j] << "," << setw(6);
else
cout << mass[i][j] << "|" << endl;
}

}
system("pause");
}

Вам также может понравиться