Primer c++ 1.2
练习1.3
编写程序,在标准输出上打印Hello, World。你好!
#include <iostream>
int main()
{
std::cout << " Hello, Wolrd " << std::endl;
return 0;
}
练习1.4
我们的程序使用加法运算符+来将两个数相加。编写程序使用乘法运算符*,来打印两个数的积。
#include <iostream>
int main()
{
int v1 = 0, v2 = 0;
std::cout << "Enter two number: " << std::endl;
std::cin >> v1 >> v2;
std::cout << "The product of " << v1 << " and " << v2 << " is " << v1 * v2 << std::endl;
return 0;
}
练习1.5
我们将所有输出操作放在一条很长的语句中。重写程序,将每个运算对象的打印操作放在一条独立的语句中。
#include <iostream>
int main()
{
int v1 = 0, v2 = 0;
std::cout << "Enter two number:" << std::endl;
std::cin >> v1 >> v2;
std::cout << "The number of ";
std::cout << v1;
std::cout << " and ";
std::cout << v2;
std::cout << " is ";
std::cout<< v1 * v2 << std::endl;
// std::cout << " The sum of " << v1;
// << " and " << v2;
// << " is " << v1 + v2 << std::endl;
return 0;
}