C 语言代码 int main() { const char *p = " **** \n" " ** ** \n" "** \n" "** \n" "** \n" " ** ** \n" " **** \n"; printf("%s", p); return 0; }
Python 代码 shape = ''' **** ** ** ** ** ** ** ** **** ''' print(shape)
C语言代码 void fun() { for (int i = 0; i <= 9; ++i) { for (int j = 1; j <= i; ++j) { printf("%d*%d=%2d ", i, j, i*j); } printf("\n"); } }
Python 代码 def fun(): for i in range(1, 10): for j in range(1, i+1): print('{0}*{1}={2:2} '.format(j, i, i*j), end='') print('')输出:
C 语言代码 void fun() { for (int i = 0; i < 8; ++i) { for (int j = 0; j < 8; ++j) { if ((i+j) % 2 == 0) printf("%c", '#'); else printf(" "); } printf("\n"); } }
Python 代码 def fun(): for i in range(8): for j in range(8): if (i+j) % 2 == 0: print('#', end='') else: print(' ', end='') print()
C 语言代码 void fun(int n) { for (int i = 0; i < n; ++i) { for (int j = 0; j <= 2*i; ++j) { printf(" "); } printf("|_\n"); } }
Python 代码 def fun(n): for i in range(n): for j in range(2*i): print(" ", end='') print("|_")
经典C语言程序设计100例 -- C 和 Python 版 (06 - 10),布布扣,bubuko.com
经典C语言程序设计100例 -- C 和 Python 版 (06 - 10)
原文:http://blog.csdn.net/xiaohui_hubei/article/details/26404963