
Voilsovke
6 год назад
Помогите написать программу, которая считает периметр двумерного массива, пожалуйста? (С++)
ОТВЕТЫ

Keyuselod
Aug 5, 2019
#include lt;stdlib.hgt;
#include lt;iostreamgt;
#include lt;iomanipgt;
using namespace std;
int main() {
const int n = 3;
const int m = 4;
int a[n][m];
int s=0;
cout lt;lt; "Исходный массив" lt;lt;endl;
srand(time(0));
for (int i = 0; i lt; n; i++){
for (int j = 0; j lt; m; j++){
a[i][j]=10+(51.0 / RAND_MAX) * rand();
cout lt;lt; fixed lt;lt; setw (7) lt;lt; a[i][j];
}
cout lt;lt;endl;
}
for (int j = 0; j lt; m; j++)
s = s+a[0][j]+a[n-1][j];
for (int i = 1; i lt; n-1; i++)
s = s+a[i][0]+a[i][m-1];
cout lt;lt; "s = " lt;lt; s lt;lt; endl;
}
Пример:
Исходный массив
55 33 24 41
50 60 41 11
17 33 45 50
s = 359
#include lt;iostreamgt;
#include lt;iomanipgt;
using namespace std;
int main() {
const int n = 3;
const int m = 4;
int a[n][m];
int s=0;
cout lt;lt; "Исходный массив" lt;lt;endl;
srand(time(0));
for (int i = 0; i lt; n; i++){
for (int j = 0; j lt; m; j++){
a[i][j]=10+(51.0 / RAND_MAX) * rand();
cout lt;lt; fixed lt;lt; setw (7) lt;lt; a[i][j];
}
cout lt;lt;endl;
}
for (int j = 0; j lt; m; j++)
s = s+a[0][j]+a[n-1][j];
for (int i = 1; i lt; n-1; i++)
s = s+a[i][0]+a[i][m-1];
cout lt;lt; "s = " lt;lt; s lt;lt; endl;
}
Пример:
Исходный массив
55 33 24 41
50 60 41 11
17 33 45 50
s = 359
54