执行输出模式必须与示例相同
do while pattern of output must be the same as example
我想知道,
在for loop
内部将此for loop
转换为do while loop
?
这是代码:
int i, j, rows;
printf("Enter number of rows: ");
scanf("%d",&rows);
for(i=1; i<=rows; ++i)
{
for(j=1; j<=i; ++j)
{
printf("* ");
}
printf("n");
}
这是我尝试的:
int i, j, rows;
printf("Enter number of rows: ");
scanf("%d",&rows);
i=1;
j=1;
do {
printf("* ");
i<=rows;
++i;
++j;
} while (j<=i);
printf("n");
getch();
return 0;
}
尽我所能,但没有运气。顺便说一句,我试图使用do while loop
进行星形模式。
在您的代码中您只有一个do while
循环,您应该使用两个嵌套的do while
循环以实现您的目标:
i=1;
j=1;
do {
do {
printf("* ");
++j;
} while (j<=i);
printf("n");
i++;
j=1;
} while(i <= rows);
测试程序:https://ideone.com/qhn3l4
相关文章:
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 无法在问题解决方案中执行输出逻辑
- 如何在程序执行时查看Valgrind Massif输出(或其他堆分析器)?
- 如何将图像传入C++可执行文件并将输出图像存储在新目录中?
- 简化C++包括变量名称和函数输出的模式
- 执行此代码时,它不显示任何输出.为什么?
- 命令模式 - 使用"weight"执行任务的命令
- Visual Studio 发布模式阻止在调试模式下执行的代码.使用 WinHTTP 和多线程
- 如何在C++中执行命令并获取命令的返回代码标准输出和标准
- 获取生成文件以更改输出可执行文件名称
- 在标准输出中执行打印会导致数组中随机分配值
- 来自不同位置的数组输出的执行时间
- C ShellexeCuteex不会通过未从该EXE产生输出来执行参数
- 执行输出模式必须与示例相同
- C++ 在代码中更改输出可执行文件名称
- 如果命令不只是打印结果,而是进入某种交互模式,如何处理来自C++的终端命令执行的输出?
- Visual Studio 2010:使用define宏指定输出可执行文件
- Borland c++ Builder 6调整输出可执行文件大小,以适应屏幕
- 将字符串映射到整型CPP -输出在执行期间挂起
- 执行可从内核模式执行的用户模式