C++ Primer 4th 习题答案 第二章

C++ Primer 4th 习题答案 第二章

返回索引

习题 2.10 使用转义字符编写一段程序,输出2M,然后换行.修改程序,输出2
跟着一个制表符,然后是M,最后是换行符
//  习题 2.10 使用转义字符编写一段程序,输出2M,然后换行.修改程序,输出2
//  跟着一个制表符,然后是M,最后是换行符

#include 
" stdafx.h "
#include 
< iostream >
using   namespace  std;


int  _tmain( int  argc, _TCHAR *  argv[])
{
    cout 
<<   " 2M "   <<   " \n " ;
    cout 
<<   " 2 "    <<   " \t "   <<   " M "   <<   " \n " ;
    getchar();
}

习题2.11 编写程序输入两个数--底数和指数,输出底数的指数次方的结果
//  习题2.11 编写程序输入两个数--底数和指数,输出底数的指数次方的结果
//

#include 
" stdafx.h "
#include 
< iostream >
using   namespace  std;


int  _tmain( int  argc, _TCHAR *  argv[])
{
    
int  result  =   1 ;
    
int   base , exponent;
    cout 
<<   " 请输入底数 " ;
    cin 
>>   base ;
    cout 
<<   " 请输入指数 " ;
    cin 
>>  exponent;

    
for  ( int  i  =   1 ; i  !=  exponent;  ++ i){
        result 
*=   base ;
    }

    cout 
<<   " 底数的指数次方为:  "   <<  result;

    getchar();
}

返回索引

你可能感兴趣的:(C++ Primer 4th 习题答案 第二章)