#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <time.h>
using namespace std;
int main()
{
const int m = 5; const int n = 7;
int a[m][n]; int s[m];
int i, j, x, temp;
srand(time(NULL)); //Инициализация генератора случайных чисел
for(i=0;i<m;i++){
for (j = 0;j < n;j++) {
a[i][j] = rand() % 9 + 1; // Случайное целое число от 1 до 9
cout << a[i][j]<<' ';
}
cout << endl;
}
for (i = 0;i < m;i++) { //Перебираем все строки
if (i % 2 == 0) { // Если строка имеет чётный номер, то
x = 0; //считаем сумму её элементов,
for (j = 0;j < n;j++)
x += a[i][j];
}
else { //иначе
x = 1; //считаем произведение её элементов
for (j = 0;j < n;j++)
x *= a[i][j];
}
s[i] = x; //Результат записываем в массив
}
// Вывод полученного одномерного массива до сортировки, если не надо, то удалите от сюда ...
cout << endl;
for (i = 0;i < m;i++)
cout << s[i] << ' ';
cout << endl;
// ... до сюда
for (i = 0;i < m - 1;i++) // Сортировка "пузырьком"
for (j = m - 1;j > i;j--)
if (s[j] < s[j - 1]) {
temp = s[j];
s[j] = s[j - 1];
s[j - 1] = temp;
}
cout << endl;
for (i = 0;i < m;i++)
cout << s[i] << ' ';
cout << endl;
return 0;
}
#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <time.h>
using namespace std;
const int m = 5;
int * * matrix_sum(int * * a, int * * b) {
int * * c = new int *[m];
for (int i = 0; i < m; i++)
c[i] = new int[m];
for (int i = 0;i < m;i++)
for (int j = 0;j < m;j++)
c[i][j] = a[i][j] + b[i][j];
return(c);
}
int matrix_norm(int * * a) {
int sum = 0;
for (int i = 0;i < m;i++)
for (int j = 0;j < m;j++)
sum += a[i][j];
return(sum);
}
int main()
{
int * * a = new int *[m], * * b = new int *[m], * * c = new int *[m], * s = new int [m], i, j, temp;
for (int i = 0; i < m; i++){
a[i] = new int[m];
b[i] = new int[m];
c[i] = new int[m];
}
srand(time(NULL));
for (i = 0;i<m;i++) {
for (j = 0;j < m;j++) {
a[i][j] = rand() % 9 + 1;
cout << a[i][j] << ' ';
}
cout << endl;
}
cout << endl;
for (i = 0;i<m;i++) {
for (j = 0;j < m;j++) {
b[i][j] = rand() % 9 + 1;
cout << b[i][j] << ' ';
}
cout << endl;
}
cout << endl;
for (i = 0;i<m;i++) {
for (j = 0;j < m;j++) {
c[i][j] = rand() % 9 + 1;
cout << c[i][j] << ' ';
}
cout << endl;
}
cout << endl;
for (i = 0;i < m;i++)
s[i] = a[i][i];
// Вывод полученного одномерного массива до сортировки, если не надо, то удалите от сюда ...
cout << endl;
for (i = 0;i < m;i++)
cout << s[i] << ' ';
cout << endl;
// ... до сюда
for (i = 0;i < m - 1;i++)
for (j = m - 1;j > i;j--)
if (s[j] < s[j - 1]) {
temp = s[j];
s[j] = s[j - 1];
s[j - 1] = temp;
}
cout << endl;
for (i = 0;i < m;i++)
cout << s[i] << ' ';
cout << endl;
cout << (matrix_norm(matrix_sum(a, c)) + matrix_norm(matrix_sum(a, b))) / matrix_norm(matrix_sum(b, c));
for (int i = 0; i < m; i++){
delete[] a[i];
delete[] b[i];
delete[] c[i];
}
delete[] a;
delete[] b;
delete[] c;
delete[] s;
return 0;
}
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.