0
Guys, help me on the following question:
Write a complete program in C language that declares a square matrix of size 5x5. Then your program must fill this matrix randomly with 0s and 1s (the matrix generated must be different with each execution of the program). Finally, your program must inform how many null rows and columns the matrix has. Follow an example of program output. In this program the user does not provide input data. Generated matrix:
1 1 0 1 0
0 0 0 0 0
0 1 0 0 0
1 0 0 1 0
1 1 0 1 0
A matriz possui 1 linha e 2 colunas nulas!
The code I made cannot read the null rows and columns:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char**argv){
int matriz[5][5];
int linha, coluna, x, count_linha, count_coluna;
srand(time(NULL));
printf("Matriz Gerada: \n");
for(linha=0; linha<5; linha++){
printf("\n");
for(coluna=0; coluna<5; coluna++){
x= rand() %2 + 0;
printf("%3d",x);
matriz[linha][coluna];
if(linha==0){
count_linha++;
}
if(coluna==0){
count_coluna++;
}
}
}
printf("\n");
printf("A matriz tem %d linhas nulas, e %d colunas nulas",count_linha, count_coluna);
}
I suggest separating your program into pieces (functions, if you already know what this is).
– Pablo Almeida
Only what your program does right is generate random numbers.
– lpacheco
Pablo’s suggestion is good, but I don’t think Stack Overflow is the place to ask people to teach you how to do your job, but to ask specific questions about how to solve problems in it.
– lpacheco