Advertisement
Gilgamesh858

elemento_In_Tre_Array

Nov 24th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     const int MAX = 5;
  10.     int a[MAX], b[MAX], c[MAX];
  11.     bool presente_B = false, presente_C = false, nessun = true;
  12.     srand(time(NULL));
  13.  
  14.     cout << "///////////////////" << endl << "A \tB \tC" << endl << endl;
  15.  
  16.     for( int i = 0; i < MAX; i++ )
  17.     {
  18.         a[i] = rand() % (rand() % 20 +1) + 1;
  19.         b[i] = rand() % (rand() % 20 +1) + 1;
  20.         c[i] = rand() % (rand() % 20 +1) + 1;
  21.  
  22.         cout << a[i] << "\t" << b[i] << "\t" << c[i] << endl << endl;
  23.     }
  24.  
  25.     for( int i = 0; i < MAX; i++)
  26.     {
  27.         for( int j = 0; j < MAX && !presente_B; j++)
  28.         {
  29.             if( a[i] == b[j] )
  30.             {
  31.                 presente_B = true;
  32.             }
  33.         }
  34.  
  35.         for( int j = 0; j < MAX && !presente_C; j++)
  36.         {
  37.             if( a[i] == c[j] )
  38.             {
  39.                 presente_C = true;
  40.             }
  41.         }
  42.  
  43.         if( presente_C && presente_B )
  44.         {
  45.             cout << endl << "/// Il Numero -> " << a[i] << " appare in tutti e tre gli array ///" << endl;
  46.             nessun = false;
  47.         }
  48.         presente_C = false;
  49.         presente_B = false;
  50.     }
  51.  
  52.     if( nessun )
  53.     {
  54.         cout << endl << "/// Nessun numero viene ripetuto nei tre array :'( ///" << endl;
  55.     }
  56.     cout << endl;
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement