Last active
January 3, 2016 02:59
-
-
Save iamandrewluca/8399546 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// #include ... | |
int numara(int ** a, int n, int m) | |
{ | |
int count = 0; | |
for (int i = 0; i < n; i++) | |
for (int j = 0; j < m; j++) | |
if (a[i][j] >= 0 && a[i][j] <=0) | |
count++; | |
return count; | |
} | |
int ** aloca(int n, int m) | |
{ | |
// alocam o matrice | |
int ** a; | |
a = (int**)malloc(n * sizeof(int*)); | |
for (int i = 0; i < n; i++) | |
a[i] = (int*)malloc(m * sizeof(int)); | |
// returnam pointerul matricii | |
return a; | |
} | |
void dealoca(int ** a, int n, int m) | |
{ | |
for (int i = 0; i < n; i++) | |
free(a[i]); | |
free(a); | |
} | |
int main() | |
{ | |
int n = 10; | |
int m = 20; | |
// matrice va lua pointerul returnal de aloca(n, m) | |
int ** matrice = aloca(n, m); | |
// lucrezi cu matricea in mod matrice[i][j] | |
int zero_unu = numara(matrice, n, m); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment