文章目录
print result:
c
//打印菱形
int main(){
int n;
int m;
scanf("%d",&n);
for(int i = 1;i <= n;i ++){
//先打印该行的n-1各空格(连续打印完)
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 ++){
//先打印该行的n-1各空格(连续打印完)
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)