Дан двумерный массив целых чисел. а) Из всех нечетных элементов массива вычесть последний элемент соот- ветствующего столбца. б) Все отрицательные элементы массива умножить на первый элемент со- ответствующей строки. в) Ко всем четным элементам массива пр
#include <iostream>
#include <stdlib.h>
#include <cstdlib>
#include <ctime>
#include <time.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
const int n = 5;
static void gen_matrix(int a[n][n]){
srand (time(NULL));
for (int i=0;i<n;i++){
for (int j=0;j<n;j++){
a[i][j]=rand() % 10+(-1);
}
}
}
static void print(int a[n][n]){
for (int i=0;i<n;i++){
for (int j=0;j<n;j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
}
int main(int argc, char** argv) {
int i, j,s1=0,s2=0;
int a[n][n];
gen_matrix(a);
print(a);
cout<<"VARIANT A"<<endl;
for ( i = 0; i < n; i++)
{
for ( j = 0; j < n; j++)
{
if (a[i][j] % 2 != 0)
a[i][j] = a[i][j] - a[i][n - 1];
}
}
print(a);
cout<<endl;
//VARINANT B
gen_matrix(a);
print(a);
cout<<"VARIANT B"<<endl;
for ( i = 0; i < n; i++)
{
for ( j = 0; j < n; j++)
{
if (a[i][j] < 0)
a[i][j] = a[i][j] * a[i][0];
}
}
print(a);
cout<<endl;
//VARIANT V
gen_matrix(a);
print(a);
cout<<"VARIANT V"<<endl;
for ( i = 0; i < n; i++)
{
for ( j = 0; j < n; j++)
{
if (a[i][j] % 2 == 0)
a[i][j] =a[i][j]+a[i][n - 1];
else
a[i][j] =a[i][j] +a[i][0];
}
}
print(a);
cout<<endl;
//VARIANT G
gen_matrix(a);
print(a);
cout<<"VARIANT G"<<endl;
for ( i = 0; i < n; i++)
{
for ( j = 0; j < n; j++)
{
if ((i + j) % 2 != 0)
a[i][j] = -1;
}
}
print(a);
cout<<endl;
return 0;
}
