YAMILDIAZ

problema 1 parcial 2

Jun 15th, 2023 (edited)
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. //DECLARACION DE FUNCIONES.
  6. // SIEMPRE SE ESPESIFCA EL SEGUNDO PARAMETRO DE LA MATRIZ.
  7. bool esMatrizSimoniana(int mSimoniana[][5]);
  8. //ESTA FUNCION SUMA CADA UNA DE LAS FILAS, EN ESTE CASO CREAMOS UN VECTOR.
  9. int sumarFila(int fila[]);
  10. bool buscarValor(int mSimoniana[][5],int valor);
  11.  
  12. int main(){
  13. //incializacion de una matriz.
  14. int matCinco[5][5]={
  15.     {1, 2, 3, 4, 5},
  16.     {5, 4, 18, 10, 11},
  17.     {1, 1, 1, 1, 1},
  18.     {9, 8, 4, 2, -5},
  19.     {10, 10, 10, 10, 10}
  20. };
  21.  
  22. if (esMatrizSimoniana(matCinco)){
  23.     cout<<"Es Matriz Simoniana."<<endl;
  24. }else{
  25.     cout<<"No es Matriz Simoniana."<<endl;
  26. }
  27.  
  28. cout<<endl;
  29. system("pause");
  30. return 0;
  31. }
  32. //DEFINICION DE FUNCION
  33. bool esMatrizSimoniana(int mSimoniana[][5]){
  34.     //f =  filas
  35.     for (int f = 0; f < 5; f++){
  36.         //suma cada filas de la matriz 5x5, cada uno de los indices de la fila de una matriz es un vector.
  37.         //podriamos decir q una matriz es un vector de vectores.
  38.         int sumar = sumarFila(mSimoniana[f]);
  39.         //cout<<"Fila #"<<f<<": "<<sumar<<endl; // ESTO FUE PARA PROBAR LA SUMA DE LAS FILAS
  40.     if (buscarValor(mSimoniana, sumar)){
  41.         return true;
  42.     }
  43.     }
  44.     return false;
  45. }
  46.  
  47. //aqui suma cada una de las filas.
  48. int sumarFila(int fila[]){
  49.     int suma=0;
  50.     for (int i = 0; i < 5; i++){
  51.         suma += fila[i];
  52.     }
  53.     return suma;
  54. }
  55. //busca el valor que da la suma de las filas en la matriz.
  56. bool buscarValor(int mSimoniana[][5],int valor){
  57.     //f = fias
  58.     for (int f = 0; f < 5; f++){
  59.         //c = columnas
  60.         for (int c = 0; c < 5; c++){
  61.             if (mSimoniana[f][c] == valor ){
  62.                 return true;
  63.             }
  64.  
  65.         }
  66.     }
  67.     return false;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment