22.輸出圖形

來源:互聯網
上載者:User

標籤:style   blog   color   os   io   檔案   for   div   

(1)1 1  21  2  31  2  3  41  2  3  4  51  2  3  4  5  6 
#include<iostream>#include <iomanip>using namespace std;int main(){    for(int i=1;i<=6;i++)    {        for(int j=1;j<=i;j++)        {            cout<<setw(2)<<j;        }        cout<<endl;    }    return 0;}//#include <iomanip>//io代表輸入輸出,manip是manipulator(操縱器)的縮寫//iomanip的作用://主要是對cin,cout之類的一些操縱運運算元,比如setfill,setw,setbase,setprecision等等。它是I/O流量控制標頭檔,就像C裡面的格式化輸出一樣.以下是一些常見的控制函數的://  dec 置基數為10 相當於"%d"//  hex 置基數為16 相當於"%X"//  oct 置基數為8 相當於"%o"//  setfill( ‘c‘ ) 設填充字元為c//  setprecision( n ) 設顯示小數精度為n位//  setw( n ) 設域寬為n個字元

 

?(2)1  2  3  4  5  61  2  3  4  5 1  2  3  41  2  3 1  2  1 
#include<iostream>#include<iomanip>using namespace std;int main(){    for(int i=6;i>=0;i--)    {        for(int j=1;j<=i;j++)        {            cout<<setw(2)<<j;        }        cout<<endl;    }    return 0;}

 

(3)                     1                 2  1             3  2  1         4  3  2  1     5  4  3  2  1 6  5  4  3  2  1 
#include<iostream>#include<iomanip>using namespace std;int main(){    for(int i=1;i<=6;i++)    {        for(int j=1;j<=6-i;j++)        {            cout<<setw(2)<<" ";        }        for(int k=i;k>0;k--)        {            cout<<setw(2)<<k;        }        cout<<endl;    }    return 0;}

 

(4)1  2  3  4  5  6    1  2  3  4  5         1  2  3  4            1  2  3                 1  2                      1 
#include<iostream>#include<iomanip>using namespace std;int main(){    for (int i=6;i>0;i--)    {        for (int j = 6-i;j>0;j--)        {            cout<<setw(2)<<" ";        }        for (int k=1;k<=i;k++)        {            cout<<setw(2)<<k;        }        cout<<endl;    }    return 0;}

 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.