用setw、cout和for循環編寫程序打印圖形


Problem Description
擬用setw、cout和for循環編寫程序,打印輸出“輸出樣例”中的圖形。請完善下面的程序:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{   
    int n;    
    //你的代碼將被嵌在這里       
    return 0;
}

Input Description
從鍵盤錄入一個正整數n,用於表示輸出圖形的行數
Output Description
按格式輸出n行星號圖形
Sample Input
4
Sample Output
   *
  ***
 *****
*******

解題代碼:

    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=i;j<n;j++){
            cout<<" ";
        }
        for(int k=1;k<i*2;k++){
            cout<<"*";
        }
        cout<<endl;
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM