怎么用c++输出下面菱形星号?

求大神解题!图形如下!请大神用for循环语句来实现!

因为不知道你是要输出三角形的星号(根据图形),还是要输出菱形的星号(根据文字),所以两个C++程序我都编写出来给你.

按照给出的图形编写的C++程序如下

#include <iostream>

using namespace std;

int main()

{

 int i,j,N=4;

 for(i=1;i<=N;i++){

  for(j=1;j<=N-i;j++){

   cout << " ";

  }

  for(j=1;j<=i*2-1;j++){

   cout << "*";

  }

  cout << endl;

 }

 return 0;

}

按照要求编写的输出菱形星号的C++程序如下

#include <iostream>

using namespace std;

int main()

{

 int i,j,N=4;

 for(i=1;i<=N;i++){

  for(j=1;j<=N-i;j++){

   cout << " ";

  }

  for(j=1;j<=i*2-1;j++){

   cout << "*";

  }

  cout << endl;

 }

 for(i=N+1;i<=2*N-1;i++){

  for(j=1;j<=i-N;j++){

   cout << " ";

  }

  for(j=1;j<=4*N-i*2-1;j++){

   cout << "*";

  }

  cout << endl;

 }

 return 0;

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-12-14
//星号金字塔
#include<bits/stdc++.h>
using namespace std;
int main(){
    
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=n-i;j>=1;j--)
{
cout<<" ";
}
for(int l=1;l<=i*2-1;l++)
{
cout<<"* ";
}
cout<<endl;
}    
    return 0;
}

第2个回答  2019-05-08
cout<<"**************"
相似回答