打印图案 题目1: 1 2 3 4 5 6 7 8 * * * * * * * * * * * * * * * * * * * * * * * * *
我写的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 #include <stdio.h> int main () { int space = 39 , star = 1 ; for (int i = 1 ;i <= 7 ;i++) { for (int j = 1 ;j <= space;j++) { printf (" " ); } for (int k = 1 ;k <= star;k++) { printf (" * " ); } if (i <= 3 ) { space -= 3 ; star += 2 ; } else { space += 3 ; star -= 2 ; } printf ("\n" ); } return 0 ; }
AI的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 #include <stdio.h> #include <math.h> #include <stdlib.h> int main () { int total_rows = 7 ; int mid = total_rows / 2 + 1 ; int initial_indent = 40 ; for (int i = 1 ; i <= total_rows; i++) { int distance = abs (mid - i); int current_star_count = 7 - (distance * 2 ); int current_space_count = initial_indent + (distance * 3 ); for (int j = 0 ; j < current_space_count; j++) { printf (" " ); } for (int k = 0 ; k < current_star_count; k++) { printf ("* " ); } printf ("\n" ); } return 0 ; }
我为啥写这篇md?
因为我得到了目前最牛逼的AI:哈基米(Gemini)
想测试一下,于是顺便写了这篇md