练习以《通过游戏编程实战教新手学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 }
程序运行结果如图:
来源:https://www.cnblogs.com/99-9/p/12547149.html