T
T
Timofey Lanevich2016-05-28 07:09:52
C++ / C#
Timofey Lanevich, 2016-05-28 07:09:52

Does not show the matrix, what is the error?

We set two matrices A(m*n), B(n*k) ,

#include <iostream>
#include <math.h>
#include "vova.h"

using namespace std;

int main(){
    int m;
    int n;
    int k;
    cout << "First matrix :\n\tm = ";
    cin >> m;
    cout << "\tn = ";
    cin >> n;
    cout << "Second matrix :\n\tn = " << n << "\n\tk = ";
    cin >> k;
    double** A = new double*[m];
    double** B = new double*[n];
    for(int i=0; i<m; i++){
        A[i] = new double[n];
    }
    for(int i=0; i<n; i++){
        B[i] = new double[k];
    }
    cout << "Matrix 1 :" << endl;
    for(int i=0; i<m; i++){
        for(int j=0; j<n; j++){
            cout << "A[" << i+1 << "][" <<j+1 << "] = " ;
            cin >> A[i][j];
            cout << "\t";

        }
        cout << endl;
    }
    cout << "Matrix 2 :" << endl;
    for(int i=0; i<n; i++){
        for(int j=0; j<k; j++){
            cout << "B[" << i+1 << "][" <<j+1 << "] = " ;
            cin >> B[i][j];
            cout << "\t";

        }
        cout << endl;
    }
    vova(m, n, k, A, B);
    return 0;
}

then transfer them to another file,
#include <math.h>

using namespace std;

double vova(int m, int n, int k, double** A, double** B){
    double minA, minB, maxA, maxB;
    for(int i=0; i<m; i++){
        for(int j=0; i<n; j++){
            if(A[i][j] < minA){
                minA = A[i][j];
            }
            if(A[i][j] > maxA){
                maxA = A[i][j];
            }
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; i<k; j++){
            if(B[i][j] < minB){
                minB = B[i][j];
            }
            if(B[i][j] > maxB){
                maxB = B[i][j];
            }
        }
    }
    cout << "Dobutok min and max matrix 1 = " << minA*maxA << "\nDobutok min and max matrix 2 = " << minB*maxB << endl;

}

and looking for the largest and smallest value of each of the matrices. It is necessary to find the maximum and minimum value of each matrix.
What is wrong here, it seems that this is not the first time I do such tasks, but this one does not work?
Probably a problem with the input of the matrix, because I just tried to output it, but it also gives me an error.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AtomKrieg, 2016-05-28
@Timak31

i < n in the vova file in the second cycles, but it should be j < n

for(int i=0; i<m; i++){
        for(int j=0; i < n; j++){

Well, you will also have problems if you do not initialize the variables like this:
minA = maxA = A[0][0];
minB = maxB = B[0][0];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question