Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int
  6. main ()
  7. {
  8. int vet1[10], vet2[10], counter[10];
  9.  
  10. for (int i = 0; i < 10; i++)
  11. {
  12. counter[i] = 0;
  13. }
  14.  
  15. cout << "Inizio input" << endl;
  16.  
  17. for (int i = 0; i < 10; i++)
  18. {
  19. cin >> vet1[i];
  20. }
  21.  
  22. cout << "fine vettore 1" << endl;
  23.  
  24. for (int i = 0; i < 10; i++)
  25. {
  26. cin >> vet2[i];
  27. }
  28.  
  29. cout << "fine vettore 2" << endl;
  30.  
  31. cout << "Verifico presenze comuni" << endl;
  32.  
  33. for (int i = 0; i < 10; i++)
  34. {
  35. for (int j = 0; j < 10; j++)
  36. if (vet1[i] == vet2[j])
  37. {
  38. cout << vet1[i];
  39. break;
  40. }
  41. }
  42.  
  43. cout << endl << "Numero maggiormente presente" << endl;
  44.  
  45. for (int i = 0; i < 10; i++)
  46. {
  47. for (int j = 0; j < 10; j++)
  48. if (vet1[i] == vet2[j])
  49. {
  50. counter[i]++;
  51. }
  52. }
  53.  
  54. int max_index = 0;
  55. for (int i = 0; i < 10; i++)
  56. {
  57. if (counter[i] > max_index)
  58. max_index = i;
  59. }
  60.  
  61. cout << vet1[max_index];
  62.  
  63.  
  64.  
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement