程序流程图练习

旧巷老猫 提交于 2020-03-22 18:16:48

 

练习以《通过游戏编程实战教新手学C++编程》书上代码做为程序流程图分析源代码。

 

Counter程序简介

  counter程序向前、向后以及每次隔5进行计数,最后绘出一个简单的坐标网格。

counter程序流程图:

 

counter程序代码如下

 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     cout << "Counting forward:\n";
 8     for (int i = 0; i < 10; ++i)
 9     {
10         cout << i << " ";
11     }
12 
13     cout << "\n\nCounting backward:\n";
14     for (int i = 9; i >= 0; --i)
15     {
16         cout << i << " ";
17     }
18 
19     cout << "\n\nCounting by fives:\n";
20     for (int i = 0; i <= 50; i += 5)
21     {
22         cout << i << " ";
23     }
24 
25     cout << "\n\nCounting with null statements:\n";
26     int count = 0;
27     for ( ; count < 10; )
28     {
29         cout << count << " ";
30         ++count;
31     }
32 
33     cout << "\n\nCounting with nested for loops:\n";
34     const int ROWS = 5;
35     const int COLUMNS = 3;
36     for (int i = 0; i < ROWS; ++i)
37     {
38         for (int j = 0; j < COLUMNS; ++j)
39         {
40             cout << i << "," << j << "  ";
41         }
42 
43         cout << endl;
44     }
45 
46     return 0;
47 }

程序运行结果如图:

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!