C语言for文循环 问题
想要最后得出以下内容,但for文只能用一次。我能用两次做出来,但用一次感觉不太现实,应为中间有一个“next,count down”感觉循环不起来啊,求教!!
Please input count number:10
Start Count Up.
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
Next, count down.
10,
9,
8,
7,
6,
5,
4,
3,
2,
1.
Finish!
#include <stdio.h> int main(void) { int i, n; printf("Please input count number:"); scanf("%d", &n); printf("Start Count Up.\n"); for(i = 1; i < 2*n; i++) { if(i <= n) printf("%d,\n", i); if(i == n) printf("Next, count down.\n"); if(i >= n) { if(i == 2 * n - 1) printf("%d.\n", 2 * n - i); else printf("%d,\n", 2 * n - i); } } printf("Finish!\n"); return 0; }