Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- //DECLARACION DE FUNCIONES.
- // SIEMPRE SE ESPESIFCA EL SEGUNDO PARAMETRO DE LA MATRIZ.
- bool esMatrizSimoniana(int mSimoniana[][5]);
- //ESTA FUNCION SUMA CADA UNA DE LAS FILAS, EN ESTE CASO CREAMOS UN VECTOR.
- int sumarFila(int fila[]);
- bool buscarValor(int mSimoniana[][5],int valor);
- int main(){
- //incializacion de una matriz.
- int matCinco[5][5]={
- {1, 2, 3, 4, 5},
- {5, 4, 18, 10, 11},
- {1, 1, 1, 1, 1},
- {9, 8, 4, 2, -5},
- {10, 10, 10, 10, 10}
- };
- if (esMatrizSimoniana(matCinco)){
- cout<<"Es Matriz Simoniana."<<endl;
- }else{
- cout<<"No es Matriz Simoniana."<<endl;
- }
- cout<<endl;
- system("pause");
- return 0;
- }
- //DEFINICION DE FUNCION
- bool esMatrizSimoniana(int mSimoniana[][5]){
- //f = filas
- for (int f = 0; f < 5; f++){
- //suma cada filas de la matriz 5x5, cada uno de los indices de la fila de una matriz es un vector.
- //podriamos decir q una matriz es un vector de vectores.
- int sumar = sumarFila(mSimoniana[f]);
- //cout<<"Fila #"<<f<<": "<<sumar<<endl; // ESTO FUE PARA PROBAR LA SUMA DE LAS FILAS
- if (buscarValor(mSimoniana, sumar)){
- return true;
- }
- }
- return false;
- }
- //aqui suma cada una de las filas.
- int sumarFila(int fila[]){
- int suma=0;
- for (int i = 0; i < 5; i++){
- suma += fila[i];
- }
- return suma;
- }
- //busca el valor que da la suma de las filas en la matriz.
- bool buscarValor(int mSimoniana[][5],int valor){
- //f = fias
- for (int f = 0; f < 5; f++){
- //c = columnas
- for (int c = 0; c < 5; c++){
- if (mSimoniana[f][c] == valor ){
- return true;
- }
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment