Advertisement
catalyn

cmmdc n perechi 2 vectrori

Oct 2nd, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5. ifstream f("date.in");
  6. ifstream ff("date2.in");
  7. ofstream g("date.out");
  8.  
  9. int cmmdc (int a, int b)
  10. {
  11. while (a != b)
  12. {
  13. if (a > b)
  14. {
  15. a = a - b;
  16. }
  17. else
  18. {
  19. b = b - a;
  20. }
  21. }
  22. return a;
  23. }
  24.  
  25. int main()
  26. {
  27. int v[100],a[100],i,j,n;
  28. f>>n;
  29. for (i=1;i<=n;i++)
  30. f>>v[i];
  31. for (j=1;j<=n;j++)
  32. ff>>a[j];
  33.  
  34. for (i=1;i<=n;i++)
  35. for (j=1;j<=n;j++)
  36. if ( cmmdc (v[i],a[j]) == 1)
  37. g<<v[i]<<" "<<a[j]<<" ";
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement