Basic C matrix

2

I've written this code for an array, everything is fine when compiling, but when I'm going to type the 3rd value it closes.

#include <stdio.h>
int main (){


    int mat[5][6];

    for (int i=0 ; i<5; i++){
        for (int f=0; f<5; f++){
            printf ("Ingresa el valor que debe quedar en la posicion %d x %d \n\n", i, f);
            scanf ("%d %d", &mat[i][f]);
        }       
    }

    for (int a=0; a<5; a++){
        for (int c=0; c<0; c++){

            printf ("El valor de la matriz es \n\n %d", mat[a][c]);
        }

    }       

    return=0

}

Thanks in advance

    
asked by Joas D 10.07.2017 в 17:00
source

1 answer

2
scanf ("%d %d", &mat[i][f]);

You set scanf to read two values but you only use one of them ... Where do you think the second one is going? it is written in a random position in the memory ...

Replace that line with

scanf ("%d", &mat[i][f]);

Another mistake they have, as you have indicated by comments is this:

return=0

For several reasons:

  • The line does not end in a semicolon
  • return is not a variable, then does not support assignments.

In this case the line should look like this:

return 0;
    
answered by 10.07.2017 / 17:15
source