我认为这会比最初计划的更容易。我试图用嵌套的 for 循环制作这张图片:
任何建议或解决方案都会有所帮助。
#include <iostream>
using namespace std;
int main()
{
for(int i=0; i<1;i++)
{
cout<<i+1<<endl;
for(int j=0;j<2;j++)
{
cout<<j+1;
}
}
cout<<"\n";
for(int k=0; k<3; k++)
{
cout<<k+1;
}
cout<<"\n";
for(int l=0; l<4; l++)
{
cout<<l+1;
}
cout<<"\n";
for(int m=4; m>0; m--)
{
cout<<m;
}
cout<<"\n";
for(int n=3; n>0; n--)
{
cout<<n;
}
cout<<"\n";
for(int o=2; o>0; o--)
{
cout<<o;
}
cout<<"\n";
for(int p=0; p<1; p++)
{
cout<<p+1;
}
cin.get();
return 0;
}
最佳答案
这里有一个 C 语言的解决方案 =)
#include <stdio.h>
#include <string.h>
int main(void) {
char forward[5] = "1";
char reverse[5] = "4321";
int i;
for( i = 1; i <= 4; i++ ) {
printf( "%s\n", forward );
forward[i] = forward[i-1]+1;
}
for( i = 0; i < 4; i++ ) printf( "% 4s\n", reverse+i );
}
关于C++ 嵌套 For 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14888238/