21xrx.com
2025-04-01 20:10:44 Tuesday
文章检索 我的文章 写文章
谭浩强C++第三版第二章课后答案
2023-07-02 11:41:35 深夜i     14     0
谭浩强 C++ 第三版 第二章 课后答案

谭浩强的C++第三版是一本非常经典的编程教材,对于初学者来说非常有用。本书第二章是C++基础语法的讲解,其中包含了很多重要的知识点。以下是第二章课后习题的答案,供读者参考。

1. 程序的输出是什么?

#include <iostream>
using namespace std;
int main()
 cout << "Hello

答:输出Hello, world!,并换行。

2. 程序的输出是什么?

#include <iostream>
using namespace std;
int main()
{
 cout << "12 + 34 = " << 12 + 34 << endl;
 return 0;
}

答:输出12 + 34 = 46,并换行。

3. 程序的输出是什么?

#include <iostream>
using namespace std;
int main()
{
 cout << (2 + 3) * 4 << endl;
 return 0;
}

答:输出20,并换行。

4. 程序的输出是什么?

#include <iostream>
using namespace std;
int main()
 cout << "I am " << 20 << " years old." << endl;
 return 0;

答:输出I am 20 years old.,并换行。

5. 程序的输出是什么?

#include <iostream>
using namespace std;
int main()
 int a

答:输出a = 3, b = 4,并换行。

6. 程序的输出是什么?

#include <iostream>
using namespace std;
int main()
{
 int a = 3, b = 4;
 a = a + b;
 b = a - b;
 a = a - b;
 cout << "a = " << a << ", b = " << b << endl;
 return 0;
}

答:输出a = 4, b = 3,并换行。这个程序实现了两个变量的交换。

7. 程序的输出是什么?

#include <iostream>
using namespace std;
int main()
{
 int a = 2, b = 3, c = 4;
 cout << a * b + c-- << endl;
 cout << a * (b + c--) << endl;
 cout << ++c << endl;
 return 0;
}

答:输出10、14、4,并换行。

以上是第二章题目的答案,每个题目都有特定的知识点,例如输出语句、运算符的使用、变量的定义和交换等。学习C++语言是一个艰苦的过程,需要通过不断的练习来提高自己的编程能力。大家可以多写编程习题,通过自我训练,逐渐掌握语言的精髓。

  
  

评论区

请求出错了