题目描述
输入一个整数n,(1<=n<=20),输出一个空心菱形,其中每个边由n个'*'组成。
输入
输入包含一个整数,n(1<=n<=20)
输出
输出一个空心菱形,每个边由n个'*'组成
样例输入
5
样例输出
** ** ** * * ** ** ** **
#include<stdio.h>
#include<stdlib.h>
#include<math.h>int main(){int n;scanf("%d",&n);for (int i = 0; i < n; i++) //输出上半个菱形{for (int j = 0; j < n-1-i; j++){printf(" ");}for (int j = 0; j < 2*i+1; j++){if (j == 0 || j == 2 * i){printf("*");}else{printf(" ");}}printf("\n");}for (int i = 0; i < n-1; i++)//输出下半个菱形{for (int j = 0; j < i + 1; j++){printf(" ");}for (int j = 0; j <2*(n-i)-3; j++){if (j == 0 || j == 2*(n-i)-4){printf("*");}else{printf(" ");}}printf("\n");}}