//简单
// main.cpp
// Print_xing
//
// Created by duanqibo on 2019/7/1.
// Copyright © 2019年 duanqibo. All rights reserved.
// 输出由“*”组成的菱形
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char * argv[])
{
int i,j,k,m,n,size;
printf("请输入对角线‘*’的个数:");
scanf("%d",&size);
if(size<0 || size%2==0)
{
printf("the size is error!\n");
exit(-1);
}
for(i=1;i<=size;i++)
{
n=(i<=(size+1)/2) ? i:size-i+1;
n=2*n-1;
m=(size-n)/2+15;
for(k=1;k<=m;k++)
printf(" ");
for(j=1;j<=n;j++)
printf("*");
printf("\n");
}
return 0;
}
运行结果: