Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. #define ROW 3
  9. #define COL 4
  10.  
  11. void pop(int **mat, vector<int> list){
  12. int count = 0;
  13. for(int x = 0;x < ROW;x++){
  14. for(int y = 0;y < COL;y++){
  15. mat[x][y] = list[count];
  16. count++;
  17. }
  18. }
  19. }
  20. void find_mat(int num, int **mat, int &r, int &c){
  21. for(int x = 0;x < ROW;x++){
  22. for(int y = 0;y < COL;y++){
  23. if(mat[x][y] == num){
  24. r = x;
  25. c = y;
  26. return;
  27. }
  28. }
  29. }
  30. }
  31. void prnt_mat(int **mat){
  32. for(int x = 0;x < ROW;x++){
  33. cout << "\t";
  34. for(int y = 0;y < COL;y++){
  35. cout << mat[x][y] << "\t";
  36. }
  37. cout << endl;
  38. }
  39. }
  40. int** crt_mat(){
  41. int **mat = new int*[ROW];
  42. for(int x = 0;x < 3;x++){
  43. mat[x] = new int[COL];
  44. }
  45. return mat;
  46. }
  47. int main() {
  48. int r = -1;
  49. int c = -1;
  50. int num;
  51. vector<int> list;
  52. int **mat = crt_mat();
  53. cin >> num;
  54. for(int x = 0;x < ROW*COL;x++){
  55. int tmp;
  56. cin >> tmp;
  57. list.push_back(tmp);
  58. }
  59. pop(mat, list);
  60. find_mat(num, mat, r, c);
  61. cout << "Matriz leida" << endl;
  62. prnt_mat(mat);
  63. cout << "Posicion del dato " << num << endl;
  64. cout << "Fila: " << r << endl;
  65. cout << "Columna: " << c;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement