thinkinjava2English
Thinking in Java,
2nd Edition, Release 11
To be published by Prentice-Hall MID-June, 2000
Bruce Eckel, President,
MindView, Inc.
Planet PDF brings you the Portable Document
Format (PDF) version of Thinking in Java (2nd
Edition). Planet PDF is the premier PDF-related
site on the web. There is news, software, white
papers, interviews, product reviews, Web links,
code samples, a forum, and regular articles by
many of the most prominent and respected PDF
experts in the world. Visit our sites for more detail:
http://www.planetpdf.com/
http://www.codecuts.com/
http://www.pdfforum.com/
http://www.pdfstore.com/
標(biāo)簽:
thinkinjava2English
Prentice-Hall
published
Thinking
上傳時(shí)間:
2014-01-15
上傳用戶(hù):ANRAN
河內(nèi)塔問(wèn)題
#include<stdio.h>
#include<stdlib.h>
int fun_a(int)
void fun_b(int,int,int,int)
int main(void)
{
int n
int option
printf("題目二:河內(nèi)塔問(wèn)題\n")
printf("請(qǐng)輸入要搬移的圓盤(pán)數(shù)目\n")
scanf("%d",&n)
printf("最少搬移的次數(shù)為%d次\n",fun_a(n))
printf("是否顯示移動(dòng)過(guò)程? 是請(qǐng)輸入1,否則輸入0\n")
scanf("%d",&option)
if(option==1)
{
fun_b(n,1,2,3)
}
system("pause")
return 0
}
int fun_a(int n)
{
int sum1=2,sum2=0,i
for(i=n i>1 i--)
{
sum1=sum1*2
}
sum2=sum1-1
return sum2
}
void fun_b(int n,int left,int MID,int right)
{
if(n==1)
printf("把第%d個(gè)盤(pán)子從第%d座塔移動(dòng)到第%d座塔\n",n,left,right)
else
{
fun_b(n-1,left,right,MID)
printf("把第%d個(gè)盤(pán)子從第%d座塔移動(dòng)到第%d座塔\n",n,left,right)
fun_b(n-1,MID,left,right)
}
}
標(biāo)簽:
int
include
stdlib
fun_a
上傳時(shí)間:
2016-12-08
上傳用戶(hù):努力努力再努力