Консультация № 202344
16.03.2022, 16:23
0.00 руб.
0 1 0
Уважаемые эксперты! Пожалуйста, ответьте на вопрос:
Дописать функцию рекурсии.
// Найти НОД (наибольший общий делитель) двух натуральных чисел.
#include <iostream>
#include <stdio.h>
#include <string>
#include <fstream>
using namespace std;
int nod(int a, int b) // наибольший делитель
{
int res;
int c = (a > b) ? b : a;
for (int i = 1; i <= c; i++)
if ((a % i == 0) && (b % i == 0))
res = i;
return res;
}

int rec(int a, int b)
{

}

int main()
{
string pach = "FileDate";
ofstream output;
output.open(pach);

if (!output.is_open())
{
cout << "Ошибка при открытии файла";
}
else
{
cout << "Файл сейчас открыт" << endl;
}
setlocale(LC_ALL, "Russian");
srand(time(0)); // для времени
int a;
int b;
int res;
cout << "Vvedite" << endl;
cin >> a;
cin >> b;
output << "Vvedite" << endl << a << endl << b << endl;
cout << "Otvet" << endl << nod(a,b) << endl;
output << "Otvet" << endl << nod(a, b) << endl;
cout << "runtime = " << clock() / 1000.0 << endl; // время работы программы
output << "runtime = " << clock() / 1000.0 << endl; // время работы программы
system("pause");
return 0;
}

Обсуждение

давно
Модератор
137394
1850
16.03.2022, 19:29
общий
Цитата: Вычисление НОД рекурсией!
https://www.cyberforum.ru/cpp-beginners/thread512092.html
Об авторе:
Понеже не словес красных бог слушает, но дел наших хощет
Форма ответа