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