fork download
  1. #include <stdio.h> // printf()의 이용을 위한 헤더 파일 포함.
  2.  
  3. int count = 0; // 이동 횟수에 이용.
  4.  
  5. void Hanoi(char a, char b, char c, int n);
  6.  
  7.  
  8. // 하노이 탑 재귀함수
  9. void Hanoi(char from, char temp, char to, int n)
  10. {
  11. if (n == 1){
  12. printf("1번 원반 %c에서 %c로 이동\n", from, to);
  13. count++;
  14. }
  15. else{
  16. Hanoi(from, to, temp, n - 1);
  17. printf("%d번 원반 %c에서 %c로 이동\n", n, from, to);
  18. count++;
  19. Hanoi(temp, from, to, n - 1);
  20. }
  21.  
  22. }
  23.  
  24.  
  25. // main 함수 시작
  26. int main(void)
  27. {
  28. int n; //원반의 수
  29. printf("\n * A탑에서 C탑으로 이동하며 총 3개(A, B, C)의 탑이있다.\n\n 옮기려는 원반의 수를 적고 엔터키를 치시오.--> ");
  30.  
  31. scanf_s("%d", &n);
  32.  
  33. Hanoi('A', 'B', 'C', n); // 하노이 탑 재귀함수를 실행할 때 처음 from(시작점)을 A로 놓고
  34. // to(목적점)을 C로 놓고 시작한다.
  35. printf("\n\n [ %d ] 개의 원반을 옮기려면 [ %d ] 번 이동해야합니다.\n\n", n, count);
  36. return 0;
  37. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘main’:
prog.c:31:2: warning: implicit declaration of function ‘scanf_s’ [-Wimplicit-function-declaration]
  scanf_s("%d", &n);
  ^~~~~~~
/home/mWZ7gI/ccMVUSXf.o: In function `main':
prog.c:(.text.startup+0x21): undefined reference to `scanf_s'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty