Skip to content

Instantly share code, notes, and snippets.

@affo
Created February 7, 2016 11:36
Show Gist options
  • Save affo/e3da7650b03d776412ee to your computer and use it in GitHub Desktop.
Save affo/e3da7650b03d776412ee to your computer and use it in GitHub Desktop.
#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