-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminhoca.c
48 lines (35 loc) · 900 Bytes
/
minhoca.c
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
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <stdlib.h>
int main() {
int** matriz;
int n,m;
scanf("%d %d",&n,&m);
matriz = (int**) malloc(n*sizeof(int*));
for (int i = 0; i < n; i++)
matriz[i] = (int*) malloc(m*sizeof(int));
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
scanf("%d",&matriz[i][j]);
}
int teste,maior;
for (int i = 0; i < n; i++)
{
teste = 0;
for (int j = 0; j < m; j++)
teste += matriz[i][j];
if(i == 0) maior = teste;
else if(teste > maior) maior = teste;
}
for (int j = 0; j < m; j++)
{
teste = 0;
for (int i = 0; i < n; i++)
teste += matriz[i][j];
if(teste > maior) maior = teste;
}
printf("%d\n",maior);
for (int i = 0; i < n; i++)
free(matriz[i]);
free(matriz);
}