Dav*_*yen 0 c while-loop variable-initialization
任务是while仅使用循环打印以下形状.
*
**
***
****
*****
******
*******
********
*********
Run Code Online (Sandbox Code Playgroud)
以下代码是我已经尝试过的,但不幸的是它不起作用:
#include "stdafx.h"//Visual Studio 2015
#include <stdio.h>
#include <stdlib.h>// using for command system("pause") ;
#include <math.h>
int main()
{
int i=0, k=0;
while (i < 10)
{
while (k <= i)
{
printf("*");
k++;
}
printf("\n");
i++;
}
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我不能自己调试它.有人可以为我调试这个吗?
你必须把它k=0放在循环中,使它在每个循环中都回到零.
int main() {
int i=0, k=0;
while (i < 10)
{
k=0; //<-- HERE
while (k <= i)
{
printf("*");
k++;
}
printf("\n");
i++;
}
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)