Created
February 7, 2016 11:36
-
-
Save affo/e3da7650b03d776412ee 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 <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#define N 5 | |
#define MAX 10 | |
int f (int m[][N]) { | |
int a[N * N], cont = 0, in; | |
int i, j, k; | |
for (i = 0; i < N; i++) { | |
for (j = 0; j < N; j++) { | |
in = 0; | |
for (k = 0; k < cont && !in; k++) { | |
if (m[i][j] == a[k]) { | |
in = 1; | |
} | |
} | |
if (!in) { | |
a[cont] = m[i][j]; | |
cont++; | |
} | |
} | |
} | |
return cont; | |
} | |
void print_m(int m[][N]) { | |
int i, j; | |
for (i = 0; i < N; i++) { | |
for (j = 0; j < N; j++) { | |
printf("%d\t", m[i][j]); | |
} | |
printf("\n"); | |
} | |
} | |
int main (void) { | |
int m[N][N], i, j; | |
srand(time(0)); | |
for (i = 0; i < N; i++) { | |
for (j = 0; j < N; j++) { | |
m[i][j] = rand() % MAX; | |
} | |
} | |
print_m(m); | |
printf("\n\t%d\n", f(m)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment