Advertisement
Xavistian

Matriz Examen Final

Jun 18th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. // ConsoleApplication4.cpp : main project file.
  2.  
  3. #include "stdafx.h"
  4. #include <conio.h>
  5. #include <iostream>
  6. using namespace std;
  7. using namespace System;
  8.  
  9. void GeneraMatriz(int **a, int n)
  10. {
  11.     Random x;
  12.     for (int i = 0; i < n; i++)
  13.     {
  14.         for (int j = 0; j < n; j++)
  15.         {
  16.             a[i][j] = x.Next(0, 10);
  17.            
  18.         }
  19.     }
  20. }
  21. void ImprimeMatriz (int **a, int n)
  22. {
  23.     for (int i = 0; i < n; i++)
  24.     {
  25.         for (int j = 0; j < n; j++)
  26.         {
  27.             cout << a[i][j] << ' ';
  28.         }cout << endl;
  29.     }
  30. }
  31. void CuantasVeces(int **a, int n, int patn)
  32. {
  33.     int cpat = 0;
  34.     for (int i = 0; i < n; i++)
  35.     {
  36.         for (int j = 0; j < n; j++)
  37.         {
  38.             if (a[i][j] * 100 + a[i][j+1] * 10 + a[i][j+2] == patn&&j<=n-2)cpat++;
  39.         }
  40.     }
  41.     cout << "El patron se repite " << cpat << " veces." << endl;
  42. }
  43. int main()
  44. {
  45.     int n, patn;
  46.     do {
  47.         cout << "Ingrese el tamanio de la matriz: ";
  48.         cin >> n;
  49.     } while (n < 0 || n>30);
  50.     int **matriz = new int* [n];
  51.     for (int i = 0; i < n; i++)
  52.     {
  53.         matriz[i] = new int[n];
  54.     }
  55.     do {
  56.         cout << "Ingrese el patron numerico: ";
  57.         cin >> patn;
  58.     } while (patn <= 99 || patn>=1000);
  59.     GeneraMatriz(matriz, n);
  60.     ImprimeMatriz(matriz, n);
  61.     CuantasVeces(matriz, n, patn);
  62.     _getch();
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement