好文档 - 专业文书写作范文服务资料分享网站

C++大学教程习题解答(第七版) 

天下 分享 时间: 加入收藏 我要投稿 点赞

}

6.3.4猜字游戏 #include #include #include using namespace std;

int main() {

int number; int guess; char answer;

<< \<

cout << \<

srand ( time(0) ); guess = 1+rand( ) 00; cin >> number; { }

while( (number >= 0 )&&( number <=1000 ) ) {

if( number == guess ) { };

if( number > guess) {

cout<<\;

cout <<\<> answer;

if( answer=='N' ||answer =='n' ) { }

cout<< \; cin >>number;

guess = 1+rand( ) 00; goto loop; break;

if( answer=='y' ||answer =='Y' )

<<\; cout<<\; cin >> number;

while( number >1000 )

loop:

}

}

cin >> number; }

if( number < guess) {

cout<<\; cin >> number; }

6.35

#include #include #include using namespace std;

int main() {

int number; int guess; char answer; int i=0;

<< \<

cout << \<

srand ( time(0) );

guess = 1 + rand( ) 00; cin >> number; { i=0; }

while( (number >= 0 )&&( number <=1000 ) ) {

if( number == guess ) {

if( i< 10 )

cout << \; cout << \; if( i== 10 ) if( i>10 )

cout<<\; cin >> number;

while( number >1000 )

loop:

}

}

};

cout << \;

cout <<\<> answer;

if( answer=='N' ||answer =='n' )

if( answer=='y' ||answer =='Y' ) { }

cout<< \; cin >>number;

guess = 1+rand( ) 00; goto loop; break;

<<\;

if( number > guess) { }

if( number < guess) { }

cout<<\; i++;

cin >> number;

cout<<\; i++;

cin >> number;

6.36

#include using namespace std;

int power( int, int );

int main() {

int x; int y;

}

cout << \; cin >> x >> y;

cout << \<< x << \<< y <<\<

int power( int base, int exponent ) { } 6.37(A)

#include #include using namespace std;

int Fibonacci( int );

int main() { }

int Fibonacci( int number ) {

int numA=0, numB=0, Result=1; if ( number == 0 )

return 0;

if ( number == 1 )

return Result;

{for( int counter=1; counter <= number-1; counter++ )

{numA = numB;

else else int x;

cout << \; cin >> x ;

cout << \<< x <<\<< Fibonacci( x ); if(exponent == 0 )

return 1;

if( exponent == 1 )

return base;

return base * power( base, exponent-1 ); else else

numB = Result;

Result = numA + numB; (B) 6.38

#include using namespace std; void move(char x,char y) {

cout << \

void hanoi(int n,char one,char two,char three) {

if(n==1) move(one,three); else {

hanoi(n-1,one,three,two); move(one,three);

hanoi(n-1,two,one,three); } }

int main() { int m;

cout<<\请?输o?入¨?盘¨?子á¨?数oy:\; cin>>m;

cout<<\移°?动?¥盘¨?子á¨?的ì?步?骤¨¨为a:\<

#include #include using namespace std;

double distance( double,double,double,double ); {

double x1,y1,x2,y2;

cout<<\; cin >> x1 >> y1; int main()

}

} }

return Result;

C++大学教程习题解答(第七版) 

}6.3.4猜字游戏#include#include#includeusingnamespacestd;intmain(){intnumber;intguess;charanswer;
推荐度:
点击下载文档文档为doc格式
8lwww86r4o862m61dk4v721et5ixox005np
领取福利

微信扫码领取福利

微信扫码分享