// page : 5
#include<iostream>
int main()
{
std::cout << "Enter two numbers:" << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
std::cout << "The sum of " << v1 << " and "
<< v2 << " is " << v1 + v2 << std::endl;
system("pause");
return 0;
}
// page : 10
#include<iostream>
int main()
{
int sum = 0, val = 1;
//只要Val的值小于等于10,while循环就会持续进行
while (val <= 10)
{
sum += val;
++val;
}
std::cout << "Sum of 1 to 10 inclusive is " << sum << std::endl;
system("pause");
return 0;
}
// page : 11
#include<iostream>
int main()
{
int sum = 0;
//从1加到10
for (int val = 1; val <= 10; ++val)
sum += val;
std::cout << "Sum of 1 to 10 is " << sum << std::endl;
system("pause");
return 0;
}
// page : 13
#include<iostream>
int main()
{
int sum = 0, value = 0;
//读取数据直到遇到文件尾,计算所有读入的值的和
while (std::cin >> value)//win系统的文件结束符尾ctrl+d
sum += value;
std::cout << "Sum is: " << sum << std::endl;
system("pause");
return 0;
}