Advertisement
qberik

Untitled

Oct 28th, 2021
57
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <ctime>
  3. using namespace std;
  4. int func(int x, int y)
  5. {
  6. while (x != y) {
  7. if(x > y) {
  8. x = x - y;
  9. }
  10. else {
  11. y = y - x;
  12. }
  13. }
  14.  
  15. return x;
  16. }
  17. int NOD(int a, int b) {
  18. if (a == b)
  19. return a;
  20. else
  21. if (a > b)
  22. return NOD(a - b, b);
  23. else
  24. return NOD(a, b - a);
  25. }
  26. int main() {
  27. clock_t t1{}, t2{};
  28. int c,c1, x, y;
  29. cout << "Введите числа" << endl;
  30. cin >> x;
  31. cin >> y;
  32. t1 = clock();
  33. for( int i = 0; i < 100000000; i++ )
  34. c = NOD(x, y);
  35. t1 = clock() - t1;
  36. t2 = clock();
  37. for( int i = 0; i < 100000000; i++ )
  38. c1 = func(x, y);
  39. t2 = clock() - t2;
  40. cout << "НОД=" << c <<endl;
  41. cout << "Время 1 :" << (t1) / static_cast<double>(CLOCKS_PER_SEC) << endl;
  42. cout << "НОД1=" << c1 <<endl;
  43. cout << "Время 2 :" << (t2) / static_cast<double>(CLOCKS_PER_SEC) << endl;
  44.  
  45. return 0;
  46. }
  47.  
  48.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement