fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. /*
  6. Lucas Correia, 2018
  7.  
  8.  */
  9. int procura(char nome[][50], int n, char nome_rep[50])
  10. {
  11. int i;
  12. for(i=0; i<n; i++)
  13. {
  14. if(!strcmp(nome[i],nome_rep))
  15. return 1;
  16. }
  17. return -1;
  18. }
  19.  
  20. int main(int argc, char *argv[])
  21. {
  22. char nomes[5][50], nomes_repetidos[5][50];
  23. int i=0, j=0, tamanho=0;
  24.  
  25. for(i=0; i < 5; i++)
  26. {
  27. printf("Informe o nome:");
  28. scanf(" %[^\n]s", nomes[i]);
  29. }
  30.  
  31.  
  32. for(i=0; i < 5; i++)
  33. {
  34. for(j = i+ 1; j < 5; j++)
  35. {
  36. if(strcmp(nomes[i], nomes[j])==0)
  37. {
  38.  
  39. if(procura(nomes_repetidos, tamanho, nomes[i])==-1)
  40. {
  41. strcpy(nomes_repetidos[tamanho], nomes[i]);
  42. tamanho++;
  43. }
  44. }
  45. }
  46. }
  47.  
  48. for(i=0; i<tamanho; i++ )
  49. printf("\nRepetead: %s", nomes_repetidos[i]);
  50.  
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0s 9424KB
stdin
aa
aa
aa
b
b
stdout
Informe o nome:Informe o nome:Informe o nome:Informe o nome:Informe o nome:
Repetead: aa
Repetead: b