本文共 820 字,大约阅读时间需要 2 分钟。
1.(比较无聊的循环)Change/add only one character and print '*' exactly 20 times.(there are atleast 3 solutions to this problem :-)
int main() { int i, n = 20; for (i = 0; i < n; i--) printf("*"); return 0; }解1:
int main() { int i, n = 20; for (i = 0; -i < n; i--) printf("*"); return 0; }解2:int main() { int i, n = 20; for (i = 0; i < n;n--) printf("*"); return 0; }解3:int main() { int i, n = 20; for (i = 0; i + n; i--) printf("*"); return 0; }
2. display below like:
1 212 32123 4321234 543212345解:(双重循环)
for (int i = 1; i <= n; i++) { for (int j = 2 * n - 1; j >= 1; j--) { if (Math.Abs(j - n) >= i) Console.Write(' '); else Console.Write(Math.Abs(j - n) + 1); } Console.WriteLine(); }本文转自Silent Void博客园博客,原文链接:http://www.cnblogs.com/happyhippy/archive/2008/02/03/1063261.html,如需转载请自行联系原作者