任何人都可以解释此代码
ASGEF - AFZHE
ASGEF1
UJHAHAHG - AGHBNG
在此使用C ++,我正在尝试在以下模式下打印
A ABA ABCBA ABCDCBA
答案 0 :(得分:0)
#include<iostream>
using namespace std;
int main()
{
char ch = 'A';
int i, n, j, k, l;
cout << "Enter range" << endl;
//cin >> n;
n = 5;
for (i = 0; i<n; i++)
{
for (j = n - i; j>0; j--)
{
cout << " "; // here you are providing spaces..
}
for (k = 0; k <= i; k++)
{
cout << ch++; // here you are printing forward values means abcd,,,,,
}
ch--; // decrement ch because ch was incremented extra on last iteration.
for (l = 0; l<i; l++)
{
cout << --ch; // printing values in reverse order .. in ch = 'C'
//then by doing post increment ( BA )
}
cout << "\n"; ch = 'A'; // then again initializing ch to A for further iterations.
}
return 0;
}
//对于i = 1 ch =第二个for循环后更新为'C',但在这里我们希望'B'为第三个for循环的正确顺序...
这些评论可能会解决您的疑问.....