Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- using namespace std;
- int func(int x, int y)
- {
- while (x != y) {
- if(x > y) {
- x = x - y;
- }
- else {
- y = y - x;
- }
- }
- return x;
- }
- int NOD(int a, int b) {
- if (a == b)
- return a;
- else
- if (a > b)
- return NOD(a - b, b);
- else
- return NOD(a, b - a);
- }
- int main() {
- clock_t t1{}, t2{};
- int c,c1, x, y;
- cout << "Введите числа" << endl;
- cin >> x;
- cin >> y;
- t1 = clock();
- for( int i = 0; i < 100000000; i++ )
- c = NOD(x, y);
- t1 = clock() - t1;
- t2 = clock();
- for( int i = 0; i < 100000000; i++ )
- c1 = func(x, y);
- t2 = clock() - t2;
- cout << "НОД=" << c <<endl;
- cout << "Время 1 :" << (t1) / static_cast<double>(CLOCKS_PER_SEC) << endl;
- cout << "НОД1=" << c1 <<endl;
- cout << "Время 2 :" << (t2) / static_cast<double>(CLOCKS_PER_SEC) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement