c++打印*組成的任意等腰三角形

不多說,直接上代碼

#include "stdafx.h"
#include"iostream"
#include"iomanip"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
 int a,i,m;//m控制輸出多少層※
 cout<<"please input:";
 cin>>m;
 cout<<endl;
 for(a=1;a<m+1;a++){
  cout<<setw(m+1-a);//第一個循環控制輸出每行的空格
  for(i=1;i<2*a;i++){
   cout<<"*";//第二個循環控制輸出每行的※
  }
  cout<<endl;
 }
 system("pause");
 return 0;
}

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章