Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- const int a=3,b=3,d=4,e=4;
- long A[a],B[b],C[d][e];
- bool elemComune (long x[],int y,long elemC);
- bool elemComABC (long A[],int a,long B[],int b, long C[][e],int d);
- int main()
- {
- int i,k;
- i=0;
- while (i<a)
- {
- A[i]=rand()%10+1;
- cout <<"A["<<i<<"]="<<A[i]<<"\n";
- i++;
- }
- i=0;
- while (i<b)
- {
- B[i]=rand()%10+1;
- cout <<"B["<<i<<"]="<<B[i]<<"\n";
- i++;
- }
- i=0;
- while (i<d)
- {
- k=0;
- while (k<e)
- {
- C[i][k]=rand()%10+1;
- cout <<"C["<<i<<"]["<<k<<"]="<<C[i][k]<<" ";
- k++;
- }
- cout <<"\n";
- i++;
- }
- if (elemComABC(A,a,B,b,C,d)) cout<<"Ho trovato almeno un elemento in comune" << endl;
- else cout<<"Non ho trovato alcun elemento in comune";
- return 0;
- }
- bool elemComune (long x[],int y, long elemC)
- {
- int i=0;
- while (i<y)
- {
- if (x[i]==elemC) return true;
- i++;
- }
- return false;
- }
- bool elemComABC (long A[],int a,long B[],int b, long C[][e],int d)
- {
- int i=0,k;
- while (i<d)
- {
- k=0;
- while (k<e)
- {
- if ((elemComune(A,a,C[i][k])) && (elemComune(B,b,C[i][k]))) return true;
- else k++;
- }
- i++;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement