练习3.1:使用恰当的using声明重做1.4.1节(第11页)和2.6.2节(第67页)的练习。
答:程序代码如下。
/*
*
*2015/5/14
*重做 1.4.1节点练习,3个,练习1.9,练习1.10,练习1.11
*/
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
//练习1.9
cout << "1.练习1.9:" << endl;
int sum = 0;
int i = 50;
while (i <= 100)
{
sum += i;
++i;
}
cout << "练习1.9的结果:" << sum << endl;
cout << "\t\n";
//练习1.10
cout << "2.练习1.20:" << endl;
int j = 10;
cout << "练习1.20的结果:" << endl;
while (j > 0)
{
cout << j << " ";
--j;
}
cout << endl;
cout << "\t\n";
//练习1.11
cout << "2.练习1.11:" << endl;
int v1, v2;
cout << "请输入两个整数v1,v2: "<< endl;
cin >> v1 >> v2;
cout << "练习1.11的结果:" << endl;
if (v1 > v2)
{
for (int i = v2; i <= v1 ; ++i)
cout << i << " ";
}
else
{
while (v1 <= v2)
{
cout << v1 << " ";
++v1;
}
}
cout << endl;
return 0;
}
本文详细展示了如何使用恰当的using声明重做并解析编程基础中的三个练习,包括求和、循环计数和条件输入处理。
674

被折叠的 条评论
为什么被折叠?



