fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main() {
  5. int N, repetidos = 0;
  6. printf ("Entre com N: ");
  7. scanf ("%d", &N);
  8. int *v1 = malloc(N * sizeof (int));
  9. int *aux = malloc(N * sizeof (int));
  10. int *flag = malloc(N * sizeof (int));
  11. int cont = 0;
  12. for (int i = 0; i < N; i++) {
  13. scanf ("%d", &v1[i]);
  14. int achou = 0;
  15. for (int j = 0; j < cont; j++) {
  16. if (v1[i] == aux[j]) {
  17. flag[j] = 1;
  18. achou = 1;
  19. break;
  20. }
  21. }
  22. if (!achou) {
  23. aux[cont] = v1[i];
  24. flag[cont++] = 0;
  25. }
  26. }
  27. for (int i = 0; i < cont; i++) {
  28. repetidos += flag[i];
  29. }
  30. if (repetidos > 0) {
  31. printf ("\n%d repetidos", repetidos);
  32. }
  33. }
Success #stdin #stdout 0s 2304KB
stdin
9
1
2
3
3
2
3
4
5
4
stdout
Entre com N: 
3 repetidos