递归方式的程序
// ConsoleApplication6.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
void prt(int all_location,int cur_location,int up) {
for (int i = 0; i < all_location; i++)
{
if (i <= cur_location)
{
std::cout << "X ";
}
else
{
std::cout << " ";
}
}
std::cout << "\n";
if (up)
{
cur_location++;
if (cur_location == all_location-1)
{
up = 0;
}
}
else
{
cur_location--;
if (cur_location<0)
{
return;
}
}
prt(all_location, cur_location, up);
}
int main()
{
prt(5, 0, 1);
int k;
std::cin >> k;
}
请看: https://blog.csdn.net/qq_42855675/article/details/81412200
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps: 问答会员【8折】购 ,仅需→23.2元,即可享受5次/月 有问必答服务,了解详情>>>https://t.csdnimg.cn/RW5m