-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAula Vetores e Matrizes Q2
More file actions
38 lines (35 loc) · 945 Bytes
/
Copy pathAula Vetores e Matrizes Q2
File metadata and controls
38 lines (35 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int i, j;
int linhas = 3;
int colunas = 3;
float **matriz = (float**) malloc(linhas * sizeof(float*));
int linha;
for(linha = 0; linha < linhas; linha++){
matriz[linha] = (float*) malloc(colunas * sizeof(float));
}
printf("Digite os valores para matriz.\n");
for(i = 0; i < linhas; i++){
for(j = 0; j < colunas; j++){
printf("Matriz[%d][%d]:", i, j);
scanf("%f", &matriz[i][j]);
}
}
printf("===============\n");
for(i = 0; i < linhas; i++){
for(j = 0; j < colunas; j++){
if(j == 0){
printf("\n%.0f\t", matriz[i][j]);
}
else{
printf("%.0f\t", matriz[i][j]);
}
}
}
for(linha = 0; linha < linhas; linha++){
free(matriz[linha]);
}
free(matriz);
return(0);
}