Advertisement
Guest User

Untitled

a guest
May 23rd, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. 1 /**************************************************************************
  2. 2 * Program: Assignment 5: Matrix
  3. 3 * Author: Jarrett Knodel
  4. 4 * Date: 05/16/2015
  5. 5 * Input: matrix size
  6. 6 * Output: Matrix 1, matrix 2, matrix 3
  7. 7 **************************************************************************/
  8. 8 #include<iostream>
  9. 9 #include <cmath>
  10. 10
  11. 11 using namespace std;
  12. 12
  13. 13 void newmat(int **m, int n);
  14. 14 void r_mat(int **m, int n, int i, int j);
  15. 15
  16. 16 int main()
  17. 17 {
  18. 18 int n, i, j, k, L, M;
  19. 19 cout << "what is the size of the matrix?" << endl;
  20. 20 cin >> n;
  21. 21 int m[n][n];
  22. 22 for (i = 0; i < n; i++){ //creating first matrix
  23. 23 for (j = 0; j < n; j++){
  24. 24 m[i][j] = M;//"m" is matrix, M is number
  25. 25 M += 1;
  26. 26 cout << m[i][j];
  27. 27 }
  28. 28 cout << endl;
  29. 29 }
  30. 30 cout << newmat(M, n) << endl; // new matrix
  31. 31 cout << "Recursive Array: "<< r_mat(m, n, 0, 0) << endl;//recursive matri x
  32. 32 }
  33. 33
  34. 34 void newmat( int **m, int n)
  35. 35 {
  36. 36 int newm[n - 1][n - 1];
  37. 37 for (int i = 0; i < (n - 1); i++){
  38. 38 for (int j = 0; j < (n - 1); j++){
  39. 39 newm[i][j] = (m[i][j] + m[i+1][j+1] + m[i+1][j+1] + m[i+1][j+1]);
  40. 40 cout << newm[i][j];
  41. 41 }
  42. 42 cout << endl;
  43. 43 }
  44. 44 }
  45. 45
  46. 45
  47. 46 void r_mat(int **m, int n, int i, int j)
  48. 47 {
  49. 48 int rm[n - 1][n - 1];
  50. 49 while (j == (n - 1)){
  51. 50 cout << endl;
  52. 51 i += 1;
  53. 52 if (i == (n - 1))
  54. 53 return 0;
  55. 54 j = 0;
  56. 55 }
  57. 56 rm[i][j] = (m[i][j] + m[i+1][j+1] + m[i+1][j+1] + m[i+1][j+1]);
  58. 57 cout << rm[i][j];
  59. 58 j += 1;
  60. 59 r_mat(m, n, i, j);
  61. 60 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement