Closed. This question is off-topic。它当前不接受答案。
想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
昨天关闭。
我编写了代码在C控制台中绘制chrismas树,但是最后一个在树下构造树干的
这是我的代码:
重要的部分是:
修正了行李箱的代码。您可以检查行李箱间距的逻辑。
想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
昨天关闭。
我编写了代码在C控制台中绘制chrismas树,但是最后一个在树下构造树干的
for
循环不起作用..有人可以帮忙吗?这是我的代码:
#include <math.h>
#include <stdio.h>
#include <stdint.h>
int breedte, invoer, boom, spatie, indent, voet, links, rechts, stam;
int i;
int main(void) { //verander dit naar Main om het programma te runnen in visual studio
printf("voer een getal in \n");
scanf_s("%d", &invoer);
breedte = 1;
boom = 1;
spatie = invoer / 2;
indent = 1;
voet = invoer / 2;
links = voet - (0.25 * invoer);
rechts = voet + (0.25 * invoer);
stam = links;
i = 10;
do {
indent = spatie;
while (indent > 0) {
printf(" ");
indent = indent - 1;
}
while (breedte > 0) {
printf("+");
breedte = breedte - 1;
}
printf("\n");
boom = boom + 2;
breedte = boom;
spatie = spatie - 1;
} while (boom <= invoer && boom <= 80);
for (int x = 0; x <= i; x++) {
while (links >= 0) {
printf(" ");
links = links - 1;
}
while (stam < rechts) {
printf("+");
stam = stam + 1;
}
printf("\n");
}
}
重要的部分是:
for (int x = 0; x <= i; x++) {
while (links >= 0) {
printf(" ");
links = links - 1;
}
while (stam < rechts) {
printf("+");
stam = stam + 1;
}
printf("\n");
}
最佳答案
#include <stdio.h>
#include <stdint.h>
#include <stdio.h>
int breedte, invoer, boom, spatie, indent, voet, links, rechts, stam;
int i,x,y;
int main(void) { //verander dit naar Main om het programma te runnen in visual studio
printf("voer een getal in \n");
scanf("%d", &invoer);
breedte = 1;
boom = 1;
spatie = invoer / 2;
indent = 1;
voet = invoer / 2;
links = voet - (0.25 * invoer);
rechts = voet + (0.25 * invoer);
stam = links;
i = 10;
do{
indent = spatie;
while (indent > 0) {
printf(" ");
indent = indent - 1;
}
while (breedte > 0) {
printf("+");
breedte = breedte -1;
}
printf("\n");
boom = boom + 2;
breedte = boom;
spatie = spatie - 1;
} while (boom <= invoer && boom <= 80);
x = links;
y = stam;
for (int xt = 0; xt <= i; xt++) {
for(int p = 0; p<x; p++) {
printf(" ");
}
x--;
for(int q=0;q<y && y<rechts; q++){
printf("+");
}
y=y+2;
printf("\n");
}
}
修正了行李箱的代码。您可以检查行李箱间距的逻辑。
关于c - 我的for循环一会儿循环不起作用吗? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59028818/