Кр по инфе
Замените элементы, стоящие на главной диагонали и значения которых четное на цифру 100
Ответы
Ответ дал:
0
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int n = 10;
int main()
{
int a[n][n];
cout << "Source array: n";
srand(time(NULL));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
a[i][j] = rand() % 500 + 100;
cout << a[i][j] << " ";
}
cout << endl;
}
cout << "New array: n";
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if ((a[i][j] % 2 == 0) && (i == j))
a[i][j] = 100;
cout << a[i][j] << " ";
}
cout << endl;
}
//system("pause");
return 0;
}
#include <stdlib.h>
#include <time.h>
using namespace std;
const int n = 10;
int main()
{
int a[n][n];
cout << "Source array: n";
srand(time(NULL));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
a[i][j] = rand() % 500 + 100;
cout << a[i][j] << " ";
}
cout << endl;
}
cout << "New array: n";
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if ((a[i][j] % 2 == 0) && (i == j))
a[i][j] = 100;
cout << a[i][j] << " ";
}
cout << endl;
}
//system("pause");
return 0;
}
Вас заинтересует
2 года назад
2 года назад
3 года назад
10 лет назад
10 лет назад