画图回顾1
我来回顾一下我所学过的画图.
首先是一个方阵.
1 长方形
1.1 同字母长方形
输入:
5 7
输出:
*******
*******
*******
*******
*******
用i控制行,用j控制列,进行输出.
循环代码:(使用请加iostream库,并且使用n,m)
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
cout<<"*";
cout<<endl;
}
完整代码:
// Copyright (C)by xff
#include <iostream>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
cout<<"*";
cout<<endl;
}
}
1.2 字母随时变的长方形
1.2.1 输出第1个数
输入:
5 7
输出:
5555555
5555555
5555555
5555555
5555555
实现代码:
// Copyright (C)by xff
#include <iostream>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
cout<<n;
cout<<endl;
}
}
1.2.2 输出行数
实现代码:
// Copyright (C)by xff
#include <iostream>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
cout<<i;
cout<<endl;
}
}
1.2.3 输出列数
// Copyright (C)by xff
#include <iostream>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
cout<<j;
cout<<endl;
}
}
1.2.拓展 输出字母 行
举例说明:
输入:
5
输出:
aaaaa
bbbbb
ccccc
ddddd
实现代码:
// Copyright (C)by xff
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
cout<<char('a'+i-1);
cout<<endl;
}
}
2 三角形
终于进入第2章了,我来喽!
这一章我要复习三角形。
2.1 同字母三角形
2.1.1从小到大的三角
输入:5
输出:
*
**
***
****
*****
实现代码:
// Copyright (C)by xff
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
cout<<"*";
cout<<endl;
}
}
2.1.2从大到小的三角
输入:5
输出:
*****
****
***
**
*
实现代码:
// Copyright (C)by xff
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
for(int i=n;i>=1;i--)
{
for(int j=1;j<=i;j++)
cout<<"*";
cout<<endl;
}
}
2.2字母随时变的三角形
2.2.1输出字母正序从小到大的三角
输入:5
输出:
1
22
333
4444
55555
实现代码:
// Copyright (C)by xff
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
cout<<i;
cout<<endl;
}
}
今天写的有点多,下次再复习点吧