请帮我将此代码转换为"$files"
循环。
do-while
这是我到目前为止所得到的......
int i,j,k;
for (i=1; i<=5; i++) {
for (j=1; j<i; j++)
cout << " ";
for (k=1; k<=6-i; k++)
cout << "$";
cout << endl;
}
我似乎无法获得正确的输出......
预期输出应为:
do{
j=5;
do{
do {
cout <<"$";
k--;
} while(k>=1);
j--;
} while (j>=i);
cout << endl;
i++;
} while(i<=5);
答案 0 :(得分:0)
试试这个:
int i = 1;
do {
int j = 1, k = 1;
if (j < i) {
do {
cout << " ";
} while (++j < i);
}
do {
cout << "$";
} while (k++ < 6 - i);
cout << endl;
} while (i++ < 5);