C++程序设计(第二版)谭浩强----程序题课后习题答案第二章

3.

复制代码
#include
using namespace std;
int main()
{
    char c1 = 'a', c2 = 'b', c3 = 'c', c4 = '\101', c5 = '\116';
    cout << c1 << c2 << c3 << '\n';
    cout << "\t\b" << c4 << '\t' << c5 << '\n';
    return 0;
}
复制代码

 

结果:

C++程序设计(第二版)谭浩强----程序题课后习题答案第二章_第1张图片

4.

复制代码
#include
using namespace std;
int main()
{
    char c1 = 'C', c2 = '+', c3 = '+';
    cout << "I say: \"" << c1 << c2 << c3 << '\"';
    cout << "\t\t" << "He says: \"C++ is very interesting!\"" << '\n';
    return 0;
}
复制代码

 

结果:

C++程序设计(第二版)谭浩强----程序题课后习题答案第二章_第2张图片

 

 5.

(1). -72.5;

(2). 11.5;

(3). 23;

(4). a = b = c = 9;

(5). a = b = 6;

(6). a = 6, b = 5;

(7). 2.5;

(8). 3 or 3.5;

 

6.

a = 12;

a += a; 24

a -= 3; 9

a *=2 + 3; 60
a /=a + a; 0
a %=(n%=2); 0
a += a -= a *= a; 0
 
7.
复制代码
#include
using namespace std;
int main()
{
    int i, j, m, n;
    i = 8;
    j = 10;
    m = ++i + j++;
    n = (++i) + (++j) + m;
    cout << i << '\t' << j << '\t' << m << '\t' << n << endl;
    return 0;
}
复制代码

 

结果:

C++程序设计(第二版)谭浩强----程序题课后习题答案第二章_第3张图片

 

8.

复制代码
#include
using namespace std;
int main()
{
    char c1 = 'C', c2 = 'h', c3 = 'i', c4 = 'n', c5 = 'a';
    int n = 4;
    c1 = c1 + n;
    c2 = c2 + n;
    c3 = c3 + n;
    c4 = c4 + n;
    c5 = c5 + n;
    cout << c1 << c2 << c3 << c4 << c5 << endl;
    return 0;
}
复制代码

 

结果:

C++程序设计(第二版)谭浩强----程序题课后习题答案第二章_第4张图片

 

相关链接:http://www.cnblogs.com/MrZheng9511/p/C2.html

你可能感兴趣的:(C++)