Write a function that receives a vector of 10 integers and returns to number of distinct numbers that compose the vector.
For example, if the given vector is v = {3, 2, 1, 3, 4, 1, 5, 5, 2}
, the function should return the number 5.
And when for example I type from 1 to 10, it returns me 1, if I type 5 numbers 1 and 5 numbers 2, it returns me 5.
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#define TAM 10
int difNumbers(int array[], int count) {
int uniqValue[count];
int n = 0;
for(int i = 0; i < count; i++) {
unsigned char foundUnique = 0;
for(int x = 0; x < count; x++) {
if(uniqValue[x] == array[i]) {
foundUnique = 1;
break;
}
}
if(foundUnique) {
uniqValue[n] = array[i];
n++;
}
}
return n;
}
int main() {
setlocale(LC_ALL, "Portuguese");
int vector[TAM], i;
for(i = 0; i < TAM; i++) {
printf("[%d]:", i+1);
scanf("%d", &vector[i]);
}
printf("%d", difNumbers(vector, TAM));
return 0;
}