Advertisement
pcsiasop

Matrices dinamicas v1

Feb 17th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<time.h>
  4. using namespace std;
  5. using namespace System;
  6.  
  7. void crearMatriz(float **&M, int cf, int cc)
  8. {
  9.     M = new float*[cf];
  10.     for (int i = 0; i <cf; i++)
  11.     {
  12.         M[i] = new float[cc];
  13.     }
  14. }
  15. void liberaMatriz(float **M, int cf)
  16. {
  17.     for (int i = 0; i < cf; i++)
  18.     {
  19.         delete[] M[i];
  20.     }
  21.     delete[] M;
  22. }
  23.  
  24. void cargaMatriz(float **M, int cf, int cc)
  25. {
  26.     srand(time(NULL));
  27.     for (int i = 0; i < cf; i++)
  28.     {
  29.         for (int j = 0; j < cc; j++)
  30.         {
  31.             M[i][j] = float(rand() % (21));
  32.         }
  33.     }
  34. }
  35. void mostrarDatos(float **M, int cf, int cc)
  36. {
  37.     for (int i = 0; i < cf; i++)
  38.     {
  39.         for (int j = 0; j < cc; j++)
  40.         {
  41.             cout<<M[i][j]<<"\t";
  42.         }
  43.         cout << endl;
  44.     }
  45. }
  46.  
  47. float hallarPromedio(float **M, int cf, int cc)
  48. {
  49.     float P3 = 0;
  50.     for (int i = 0; i < 30; i++)
  51.     {
  52.         P3 += M[i][2];
  53.     }
  54.     return P3/30;
  55. }
  56. void main()
  57. {
  58.     int cf = 30, cc = 6;
  59.     float **notas;
  60.     crearMatriz(notas, cf, cc);
  61.     cargaMatriz(notas, cf, cc);
  62.     mostrarDatos(notas, cf, cc);
  63.     cout << "Promedio de practica 3: " << hallarPromedio(notas, cf, cc) << endl;
  64.     liberaMatriz(notas, cf);
  65.     system("pause>NULL");
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement