Answer to Question #329028 in C for Rohit

Question #329028

you are given a 3x3 matrix of positive integers.You have to determine whether some row is a positive interger multiple of another. If row i is an interger multiple of row j then you have to output p#q where p is the minimum of (i,j) and q is the maximum of (i,j). If there are multiple possibilities for i and j, you have to print for smallest i and the smallest j. Otherwise, you have to output 0#0



1
Expert's answer
2022-04-17T05:09:08-0400
#include <stdio.h>
#include <stdbool.h>


#define N 3


void readMatrix(int M[N][N]) {
    int i, j;
    printf("Entre matreix %dx%d:\n", N, N);
    for (i=0; i<N; i++) {
        for (j=0; j<N; j++) {
            scanf("%d", &M[i][j]);
        }
    }
}


bool isMultilier(int row1[N], int row2[N]) {
    int i;
    int q = row1[0]/row2[0];
    
    for (i=0; i<N; i++) {
        if (row2[i]*q != row1[i])
            return false;
    }
    return true;
}


void testMatrix(int M[N][N]) {
    int i, j, p, q;
    
    p = q = -1;
    for (i=0; i<N; i++) {
        for (j=0; j<N; j++) {
            if (i != j) {
                if (isMultilier(M[i], M[j])) {
                    p = i < j ? i : j;
                    q = i < j ? j : i;
                    break;
                }
            }
        }
        if (p != -1) {
            break;
        }
    }
    printf("%d#%d\n", p+1, q+1);
}


int main() {
    int M[N][N];


    readMatrix(M);
    testMatrix(M);


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS