Advertisement
Emanuele_Bruno

Esame 1

Dec 8th, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. const int a=3,b=3,d=4,e=4;
  7.  
  8. long A[a],B[b],C[d][e];
  9.  
  10. bool elemComune (long x[],int y,long elemC);
  11. bool elemComABC (long A[],int a,long B[],int b, long C[][e],int d);
  12.  
  13. int main()
  14. {
  15.     int i,k;
  16.     i=0;
  17.     while (i<a)
  18.     {
  19.         A[i]=rand()%10+1;
  20.         cout <<"A["<<i<<"]="<<A[i]<<"\n";
  21.         i++;
  22.     }
  23.     i=0;
  24.     while (i<b)
  25.     {
  26.         B[i]=rand()%10+1;
  27.         cout <<"B["<<i<<"]="<<B[i]<<"\n";
  28.         i++;
  29.     }
  30.     i=0;
  31.     while (i<d)
  32.     {
  33.         k=0;
  34.         while (k<e)
  35.         {
  36.             C[i][k]=rand()%10+1;
  37.             cout <<"C["<<i<<"]["<<k<<"]="<<C[i][k]<<" ";
  38.             k++;
  39.         }
  40.         cout <<"\n";
  41.         i++;
  42.     }
  43.     if (elemComABC(A,a,B,b,C,d)) cout<<"Ho trovato almeno un elemento in comune" << endl;
  44.     else cout<<"Non ho trovato alcun elemento in comune";
  45.     return 0;
  46. }
  47.  
  48.  
  49. bool elemComune (long x[],int y, long elemC)
  50. {
  51.     int i=0;
  52.     while (i<y)
  53.     {
  54.         if (x[i]==elemC) return true;
  55.         i++;
  56.     }
  57.     return false;
  58. }
  59.  
  60. bool elemComABC (long A[],int a,long B[],int b, long C[][e],int d)
  61. {
  62.     int i=0,k;
  63.     while (i<d)
  64.     {
  65.         k=0;
  66.         while (k<e)
  67.         {
  68.             if ((elemComune(A,a,C[i][k])) && (elemComune(B,b,C[i][k]))) return true;
  69.             else k++;
  70.         }
  71.         i++;
  72.     }
  73.     return false;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement