- 追加された行はこのように表示されます。
- 削除された行は
このように表示されます。
// ユークリッドの互除法(再帰版)
// ハノイの塔(再帰版)
#include <iostream>
using namespace std;
int gcd ( int x, int y )
void Hanoi(int n, string from, string work, string dest)
{
int r=x%y;
while(r>0){
x=y;
y=r;
r=x%y;
if(n>=2){
Hanoi(n-1,from,dest,work);
}
return y;
cout << n << "を" << from << "から" << dest << "へ" << endl;
if(n>=2){
Hanoi(n-1,work,from,dest);
}
}
int main()
main()
{
int a,b;
cout << "a:";
cin >> a;
cout << "b:";
cin >> b;
cout << "GCD=" << gcd(a,b) << endl;
return 0;
Hanoi(3,"A","B","C");
}