Advertisement
Bidca

Almacen

May 10th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main () {
  4.  
  5.     //Se piden el numero de productos (filas) y las zonas (columnas).
  6.     int productos, zonas;
  7.     std::cin >> productos >> zonas;
  8.  
  9.     //Matriz.
  10.     int mat [productos][zonas];
  11.  
  12.     //Se pide que se llene la matriz.
  13.     for (int i = 0; i < productos; ++i){
  14.         for (int j = 0; j < zonas; ++j){
  15.             std::cin >> mat [i][j];
  16.         }
  17.     }
  18.  
  19.     //Se determinara la mayor produccion por zona.
  20.     int zona_mayor = mat [0][0];
  21.      for (int j = 0; j < zonas; ++j){
  22.         for (int i = 0; i < productos; ++i){
  23.             if (zona_mayor < mat [i][j]) {
  24.                 zona_mayor = mat [i][j];
  25.             }
  26.         }
  27.         std::cout <<"Zona "<<j + 1<<" = "<<zona_mayor<<"\n";
  28.         zona_mayor = 0;
  29.      }
  30.  
  31.     //Se determinara la mayor produccion por producto.
  32.     int producto_mayor = mat [0][0];
  33.      for (int i = 0; i < productos; ++i){
  34.         for (int j = 0; j < zonas; ++j){
  35.             if (producto_mayor < mat [i][j]) {
  36.                 producto_mayor = mat [i][j];
  37.             }
  38.         }
  39.         std::cout <<"Producto "<<i + 1<<" = "<<producto_mayor<<"\n";
  40.         producto_mayor = 0;
  41.      }
  42.  
  43.      //Se suman por zonas, para determinar el promedio.
  44.      int sum = 0;
  45.      for (int j = 0; j < zonas; ++j){
  46.         for (int i = 0; i < productos; ++i){
  47.             sum += mat [i][j];
  48.         }
  49.         std::cout <<"Promedio zona "<<j + 1<<" = "<<sum / productos<<"\n";
  50.         sum = 0;
  51.      }
  52.  
  53. /*
  54.     //Se imprime la matriz.
  55.     for (int i = 0; i < productos; ++i){
  56.         for (int j = 0; j < zonas; ++j){
  57.             std::cout << mat [i][j] << " ";
  58.         }
  59.         std::cout << "\n";
  60.     }
  61. */
  62.  
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement