Skip to content

Instantly share code, notes, and snippets.

@iamandrewluca
Last active January 3, 2016 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamandrewluca/8399546 to your computer and use it in GitHub Desktop.
Save iamandrewluca/8399546 to your computer and use it in GitHub Desktop.
// #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