-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
39 lines (31 loc) · 779 Bytes
/
main.cpp
File metadata and controls
39 lines (31 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// main.cpp
// towerOfHanoi
//
// Created by Sethupathi on 11/03/20.
// Copyright © 2020 Sethupathi. All rights reserved.
//
#include <iostream>
using namespace std;
void towerOfHanoi(char a, char b, char c, int n)
{
if(n==1)
cout<<"Moving disc "<<n<<" from "<<a<<" to "<<c<<endl;
else
{
//a source b help c dest --default
towerOfHanoi(a, c, b, n-1);
cout<<"Moving disc "<<n<<" from "<<a<<" to "<<c<<endl;
// cout<<"Moving disc"<<n<<a<<"to"<<c<<endl;
towerOfHanoi(b, a, c, n-1);
}
}
int main(int argc, const char * argv[]) {
// insert code here...
int n;
cout<<"Enter the no. of discs";
cin>>n;
// char a,b,c;
towerOfHanoi('a','b','c',n);
return 0;
}