Matrix multiplication in C

Asked

Viewed 457 times

0

I have a little problem with this show, i need in a matrix[4][4] to find the minimum maximum of each line and multiply by each number of the line, in my program it has a syntax error, because I keep the largest number and it multiplies only by the last number of each line for example:

mat[i][j]={0, 1, 2, 3,
           4, 5, 6, 7,
           8, 9, 10, 11,
           12, 13, 14, 15}

would be:

 mat[i][j]={0, 1, 2, 9,
            4, 5, 6, 49,
            8, 9, 10, 121,
            12, 13, 14, 225}

my code:

#include <stdio.h>
#include <stdlib.h>
#include <locale.h>

//achar maior menor de cada linha da matriz
int main(int argc, char *argv[]) 
{
    int mat[4][4];
    int i, j, aux;

    //le matriz
    for(i=0; i<=3; i++)
    {
        for(j=0; j<=3; j++)
        {
            setlocale(LC_ALL, "Portuguese");
            printf("digite um numero para a posição %d e coluna %d de mat:\n", i, j);
            scanf("%d", &mat[i][j]);
        }
    }

    //1ºfase de processamento
    for(i=0; i<=3; i++)
{
    for(j=0; j<=3; j++)
    {
        if(mat[i][j]>=mat[i][j])//se o elemento na posição mat={i,j} 
                                //for maior que o ultimo elemento da linha
        {
            aux=mat[i][j];//guardar em aux
            mat[i][j]=mat[i][j]*aux;
        }
    }
}

in case anyone knows what I did wrong, would like some explanation I’m having too much syntax problem.

  • if(mat[i][j]>=mat[i][j]) will always be true!

  • @pmg but saw how I do to find the largest number of each line?

1 answer

4


When j for 3, the if will access a non-existent element

if(mat[i][j]>=mat[i][j+1]) // mat[i][4] nao existe
  • i had modified in my IDE and posted the wrong code in the processing phase the mouth is found if you find differently modified in the post

Browser other questions tagged

You are not signed in. Login or sign up in order to post.