информатика

Помогите написать программу, которая считает периметр двумерного массива, пожалуйста? (С++)

Оставить ответ
1

Ответ №1

#include <stdlib.h>
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
const int n = 3;
const int m = 4;
int a[n][m];
int s=0;

cout << "Исходный массив" <<endl;
srand(time(0));
for (int i = 0; i < n; i++){
 for (int j = 0; j < m; j++){
a[i][j]=10+(51.0 / RAND_MAX) * rand();
cout << fixed << setw (7) << a[i][j];
 }
cout <<endl;
}
 for (int j = 0; j < m; j++)
  s = s+a[0][j]+a[n-1][j];
 for (int i = 1; i < n-1; i++)
  s = s+a[i][0]+a[i][m-1];
cout << "s = " << s << endl;
}

Пример:
Исходный массив

  55 33 24 41

  50 60 41 11

  17 33 45 50

s = 359

Знаете ответ?