菱形块

 #include "iostream.h"
void main()
{
   int a,b,c,d,i,f;
   cout<<"请输入一个奇数:";
   cin>>a;
   b=int(a/2)+1;
   for(i=1;i<=b;i++)
   {
    for (c=1;c<=b-i;c++)
    {
     cout<<" ";
    }
    for (c=1;c<=i*2-1;c++)
    {
     cout<<"*";
    }
    cout<<endl;
   }
     f=(a-b)*2-1;
   for (d=1;d<=a-b;d++)
   
   {
    for (c=1;c<=d;c++)
    {
     cout<<" ";
    }
    for (c=1;c<=f;c++)
    {
     cout<<"*";
    }
    cout<<endl;
    f-=2;
   
   }
}

根据前两个三角形的思路,我又编写出一个菱形,攻打公大家参考!!

原文地址:https://www.cnblogs.com/qiqiBoKe/p/2791633.html