fork download
  1. #include <iostream>
  2. #include <ctime>
  3. #include <stdlib.h>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. setlocale(LC_ALL, "Russian");
  10. const int N=10;
  11. int x[N];
  12. int y[N];
  13. int z[2*N];
  14. int k;
  15. int j,i;
  16. srand(time(NULL));
  17. for (int i=0; i<N; i++)
  18. x[i]=rand()%20;
  19.  
  20. /* вывод массива на экран */
  21. cout << " массив x" << endl;
  22. for (int i=0; i<N; i++)
  23. cout << setw(4) << x[i];
  24. cout << endl;
  25.  
  26.  
  27. for (int j=0; j<N; j++)
  28. y[j]=rand()%20;
  29.  
  30. /* вывод массива на экран */
  31. cout << " массив y" << endl;
  32. for (int j=0; j<N; j++)
  33. cout << setw(4) << y[j];
  34. cout << endl;
  35. k=0;
  36.  
  37. for (int i=0; i<N; i++)
  38.  
  39. for (int j=0; j<N; j++)
  40. {
  41. if(x[i]==y[j]){
  42. z[k]=x[i];
  43. k++;}
  44. }
  45.  
  46. cout << "массив z" << endl;
  47. for (int i=0; i<k; i++)
  48. cout << setw(4) << z[i];
  49. cout << endl;
  50.  
  51. if ((x[i]!=y[j])&&(k==1))
  52.  
  53. cout << "пересечения нет" << endl;
  54.  
  55.  
  56.  
  57. system("pause");
  58. return 0;
  59. }
Success #stdin #stdout #stderr 0s 4528KB
stdin
Standard input is empty
stdout
 массив x
   9   6  17   5  14   2   8  10   8  14
 массив y
  15   1   0   1   8   2   3  17  15  14
массив z
  17  14   2   8   8  14
stderr
sh: pause: not found