您的位置:首页 > 其它

1.2. 初窥输入/输出

2015-06-18 16:02 190 查看
Exercise 1.3: Write a program to print "Hello, World" on the standard output.

编一个程序,在标准输出上打印“Hello, World”。
int main(void){cout << "Hello,world" << endl;return 0;}
Exercise 1.4: Our program used the built-in addition operator, +, to generate the sum of two numbers. Write a program that uses the multiplication operator, *, to generate the product of two numbers.我们的程序利用内置的加法操作符“+”来产生两个数的和。编写程序,使用乘法操作符“*”产生两个数的积。 #include <iostream>using namespace std;int main(void){int val1 = 0,val2 = 0;cout << "Please input two numbers:";cin >> val1 >> val2;cout << val1 << "*" << val2 << " = " << val1*val2 << endl;return 0;}Exercise 1.6: Explain what the following program fragment does:解释下面的程序段:   std::cout << "The sum of " << v1;             << " and " << v2;             << " is " << v1 + v2             << std::endl;Is this code legal? If so, why? If not, why not?这段代码合法吗?如果合法,为什么?如果不合法,又为什么? 答:非法。因为1,2,4句有分号,形成单独的一句。234没有左操作数。
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: