首页 > 代码库 > 22.输出图形
22.输出图形
(1)
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;}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。