zoukankan      html  css  js  c++  java
  • 22.输出图形

    (1)
    1  2
    1  2  3
    1  2  3  4
    1  2  3  4  5
    1  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  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=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;
    }

  • 相关阅读:
    动态规划算法1——背包问题
    图论——Dijkstra算法
    C++的输入和输出
    org.hibernate.type.SerializationException: could not deserialize 反序列化失败
    当json串传输异常(乱码破坏格式),服务器不能解析时,可以截取串达到取值的目的
    ReferenceError: ** is not defined
    jar包反复下载不成功
    include与.jspf
    url中“/”的意义
    JSP取得绝对路径
  • 原文地址:https://www.cnblogs.com/jixiaowu/p/3894683.html
Copyright © 2011-2022 走看看