print result:

c
| |
| #include <stdio.h> |
| int main(){ |
| int n; |
| int m; |
| scanf("%d",&n); |
| for(int i = 1;i <= n;i ++){ |
| |
| for(int j = 0;j < n - i;j ++){ |
| printf(" "); |
| } |
| |
| for(int k = 0;k < 2 * i - 1;k++){ |
| printf("*"); |
| } |
| printf("\n"); |
| } |
| for(int i = 1;i < n;i ++){ |
| |
| for(int j = 0;j < i;j ++){ |
| printf(" "); |
| } |
| |
| m = 2 * n - 1; |
| for(int k = 0;k < m - 2 * i;k++){ |
| printf("*"); |
| } |
| printf("\n"); |
| } |
| } |
python
| def print_up_triangle(n): |
| """ to count the space of each line: """ |
| j=n-1 |
| for i in range(0,n): |
| print(j*' '+(i*2+1)*'*') |
| j-=1 |
| |
| def print_down_triangle(n): |
| """ to count the space of each line: """ |
| j=1 |
| for i in range(n-2,-1,-1): |
| print(j*' '+(2*i+1)*'*') |
| j+=1 |
| """ the scale n is the sequence:n= 0,1,2,3,...n """ |
| def print_diamond(n): |
| print_up_triangle(n) |
| print_down_triangle(n) |
| scale=input("input a integer to specify the scale of the diamond to be print: ") |
| scale=(int)(scale) |
| print_diamond(scale) |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了