157、为以下每种情况编写一个for语句:a. 使用名为i的计数器,初始值为1,最终值为20,增量为1。b. 使用名为icount的计数器,初始值为1,最终值为20,增量为2。c. 使用名为j的计数器,初始值为1,最终值为100,增量为5。d. 使用名为icount的计数器,初始值为20,最终值为1,增量为 - 1。e. 使用名为icount的计数器,初始值为20,最终值为1,增量为 - 2。f. 使用名为count的计数器,初始值为1.0,最终值为16.2,增量为0.2。g. 使用名为xcnt的计数器,初始值为20.0,最终值为10.0,增量为 - 0.5。
- a.
for (i = 1; i <= 20; i = i + 1)或for (i = 1; i <= 20; ++i) - b.
for (icount = 1; icount <= 20; icount = icount + 2) - c.
for (j = 1; j <= 100; j = j + 5) - d.
for (icount = 20; icount >= 1; icount = icount - 1)或for (icount = 20; icount >= 1; --icount) - e.
for (icount = 20; icount >= 1; icount = icount - 2) - f.
for (count = 1.0; count <= 16.2; count = count + 0.2) - g.
for (xcnt = 20.0; xcnt >= 10.0; xcnt = xcnt - 0.5)
158、确定以下每个for循环的执行次数:a. 初始值为1,终值为20,增量为1;b. 初始值为1,终值为20,增量为2;c. 初始值为1,终值为100,增量为5;d. 初始值为20,终值为1,增量为 -1;e. 初始值为20,终值为1,增量为 -2;f. 初始值为1.0,终值为16.2,增量为0.2;g. 初始值为20.0,终值为10.0,增量为 -0.5。
- a. 初始值为1,终值为20,增量为1,循环执行20次;
- b. 初始值为1,终值为20,增量为2,循环执行10次;
- c. 初始值为1,终值为100,增量为5,循环执行20次;
- d. 初始值为20,终值为1,增量为 -1,循环执行20次;
- e. 初始值为20,终值为1,增量为 -2,循环执行10次;
- f. 初始值为1.0,终值为16.2,增量为0.2,循环执行76次;
- g. 初始值为20.0,终值为10.0,增量为 -0.5,循环执行20次。
159、确定以下每个循环执行后 total 的值:a. total 初始化为 0;使用 for 循环,i 从 1 到 10 每次递增 1,每次循环 total 加 1。b. total 初始化为 1;使用 for 循环,count 从 1 到 10 每次递增 1,每次循环 total 乘以 2。c. total 初始化为 0;使用 for 循环,i 从 10 到 15 每次递增 1,每次循环 total 加上 i。d. total 初始化为 50;使用 for 循环,i 从 1 到 10 每次递增 1,每次循环 total 减去 i。e. total 初始化为 1;使用 for 循环,icnt 从 1 到 8 每次递增 1,每次循环 total 乘以 icnt。f. total 初始化为 1.0;使用 for 循环,j 从 1 到 5 每次递增 1,每次循环 total 除以 2.0。
- a. total 的最终值为 10。
- b. total 的最终值为 1024。
- c. total 的最终值为 75。
- d. total 的最终值为 50 - (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10) = 50 - 55 = -5。
- e. total 的最终值为 8 的阶乘,即 40320。
- f. total 的最终值为 1.0 / (2.0 * 2.0 * 2.0 * 2.0 * 2.0) = 0.03125。
160、确定以下程序的输出:#include using namespace std; int main() { int i; for (i = 20; i >= 0; i = i - 4) cout << i << ” “; return 0; }
程序的输出为:20 16 12 8 4 0
161、编写一个C++程序,将千米/小时转换为英里/小时。该程序应生成一个包含10次转换的表格,从60千米/小时开始,每次递增5千米/小时。显示应包含适当的标题,并列出每个千米/小时及其等效的英里/小时值。使用1千米 = 0.6241英里的换算关系。
以下是满足需求的C++程序:
#include <iostream>
#include <iomani

最低0.47元/天 解锁文章
1442

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



