
C++题目,高手请进.
用循环语句编程,分别显示如下3个图形。(1)333333332222233211123321012332111233333333(2)444433333333333322...
用循环语句编程,分别显示如下3个图形。
(1) 3 3 3 3 3 3 3
3 2 2 2 2 2 3
3 2 1 1 1 2 3
3 2 1 0 1 2 3
3 2 1 1 1 2 3
3 3 3 3 3 3 3
(2)
4
4 4 4
3 3 3 3 3
3 3 3 3 3 3 3
2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2
1 1 1 1 1
1 1 1
0
(3) 4
4 3 4
4 3 2 3 4
4 3 2 1 2 3 4
4 3 2 1 0 1 2 3 4
4 3 2 1 2 3 4
4 3 2 3 4
4 3 4
4 展开
(1) 3 3 3 3 3 3 3
3 2 2 2 2 2 3
3 2 1 1 1 2 3
3 2 1 0 1 2 3
3 2 1 1 1 2 3
3 3 3 3 3 3 3
(2)
4
4 4 4
3 3 3 3 3
3 3 3 3 3 3 3
2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2
1 1 1 1 1
1 1 1
0
(3) 4
4 3 4
4 3 2 3 4
4 3 2 1 2 3 4
4 3 2 1 0 1 2 3 4
4 3 2 1 2 3 4
4 3 2 3 4
4 3 4
4 展开
1个回答
展开全部
#include <iostream>
#include <iomanip>
using namespace std;
void f1( int n )
{
for ( int i=-n; i<=n; ++i ) {
for ( int j=-n; j<=n; ++j ) {
cout << ((abs(i)>=abs(j)) ? abs(i) : abs(j) );
}
cout << endl;
}
cout << endl;
}
void f2( int n )
{
for ( int i=2*n; i>=0; --i ) {
for ( int j=0; j<=2*(n-abs(i-n)); ++j ) {
cout << (i+1)/2;
}
cout << endl;
}
cout << endl;
}
void f3( int n )
{
for ( int i=-n; i<=n; ++i ) {
cout << setw(abs(i)+1);
for ( int j=-(n-abs(i)); j<=(n-abs(i)); ++j ) {
cout << abs(i)+abs(j);
}
cout << endl;
}
cout << endl;
}
int main()
{
f1( 3 );
f2( 4 );
f3( 4 );
return 0;
}
#include <iomanip>
using namespace std;
void f1( int n )
{
for ( int i=-n; i<=n; ++i ) {
for ( int j=-n; j<=n; ++j ) {
cout << ((abs(i)>=abs(j)) ? abs(i) : abs(j) );
}
cout << endl;
}
cout << endl;
}
void f2( int n )
{
for ( int i=2*n; i>=0; --i ) {
for ( int j=0; j<=2*(n-abs(i-n)); ++j ) {
cout << (i+1)/2;
}
cout << endl;
}
cout << endl;
}
void f3( int n )
{
for ( int i=-n; i<=n; ++i ) {
cout << setw(abs(i)+1);
for ( int j=-(n-abs(i)); j<=(n-abs(i)); ++j ) {
cout << abs(i)+abs(j);
}
cout << endl;
}
cout << endl;
}
int main()
{
f1( 3 );
f2( 4 );
f3( 4 );
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询