52 lines
1.0 KiB
C++
52 lines
1.0 KiB
C++
//Cristian Ronzoni 3Ain
|
|
//Verifica se tutte le celle dei “bordi” contengono lo stesso valore
|
|
#include <iostream>
|
|
#include <iomanip>
|
|
#include <cstdlib>
|
|
#include <ctime>
|
|
#define NUM 4
|
|
using namespace std;
|
|
void stampaMatrice(int matrice[NUM][NUM]) {
|
|
cout << "Matrice:\n";
|
|
for (int i = 0; i < NUM; ++i) {
|
|
for (int j = 0; j < NUM; ++j) {
|
|
cout << matrice[i][j] << " ";
|
|
}
|
|
cout << endl;
|
|
}
|
|
}
|
|
bool verificaBordiUguali(int arr[NUM][NUM]){
|
|
|
|
int valoreBordo = arr[0][0];
|
|
|
|
for(size_t j =0; j<NUM; ++j){
|
|
if(arr[0][j] != valoreBordo || arr[NUM-1][j] != valoreBordo){
|
|
return false;
|
|
}
|
|
}
|
|
|
|
for(size_t i = 0; i<NUM; ++i){
|
|
if(arr[i][0] != valoreBordo || arr[i][NUM-1] != valoreBordo){
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
int main(void){
|
|
|
|
int bobby[NUM][NUM]{
|
|
1,1,1,1,
|
|
1,0,0,1,
|
|
1,0,0,1,
|
|
1,1,1,1
|
|
};
|
|
stampaMatrice(bobby);
|
|
verificaBordiUguali(bobby);
|
|
if(verificaBordiUguali(bobby))
|
|
cout << endl<< "La matrice ha tutti i bordi uguali";
|
|
else
|
|
cout << "no";
|
|
|
|
}
|