C++ c+中的弗洛伊德图案+;

C++ c+中的弗洛伊德图案+;,c++,C++,嗨,我正在尝试用c打印以下图案++ 1 2 3 4 5 6 7 8 9 10 7 8 9 10 4 5 6 2 3 1 使用下面的循环打印它的一半 int i,j,k=1; cout<<"Enter row"; cin>>n; for(i=1;i<=n;i++) { for(j=1;j<=i;j++) { cout<<k<<"\t"; k++; } } 如何打印余额输出。但是如何打印此图案的镜像。首先,上

嗨,我正在尝试用c打印以下图案++

1
2 3
4 5 6
7 8 9 10
7 8 9 10
4 5 6
2 3
1
使用下面的循环打印它的一半

int i,j,k=1;
cout<<"Enter row";
cin>>n;
for(i=1;i<=n;i++)
{
  for(j=1;j<=i;j++)
  {
    cout<<k<<"\t";
    k++;
  }
}

如何打印余额输出。但是如何打印此图案的镜像。

首先,上面的代码是错误的,应该是:

for(i=1;i<=n;i++)
{
  for(j=1;j<=i;j++)
  {
    cout<<k<< " ";
    k++;
  }

  cout << '\n';
}
for(i=1;i
intmain()
{
int n;
int i,j,k=1;
cout>n;
int elemcount=0;

对于(i=1;我是的,只是在一个在线编译器上运行它。多次。为什么?@Nishant仍然看不出这段代码有任何问题。为什么你问我是否测试过它?现在工作正常,它给了我一些错误,你还说你注意到了一些问题。是的,我认为这是一个问题,但意识到这只是一个格式问题-看起来好像有一个额外的数字(由于从一位数跳到两位数),但当我从空格切换到标签时,它看起来很好。除了回答这样的问题之外,我看没有其他人(没有否决票)下次会小心:(
for(i=1;i<=n;i++)
{
  for(j=1;j<=i;j++)
  {
    cout<<k<< " ";
    k++;
  }

  cout << '\n';
}
for(;i > 0; i--)
{
    k -= i-1;

    for(j=1;j<i;j++)
    {
        cout <<k<< " ";
        k++;
    }

    cout << '\n';
    k -= i-1;
}
int main()
{
    int n;
    int i, j, k = 1;
    cout << "Enter row";
    cin >> n;
    int elemcount = 0;
    for (i = 1; i <= n; i++)
    {
        elemcount = 0;
        for (j = 1; j <= i; j++)
        {

            cout << k << "\t";
            k++;
        }
        cout <<endl;
    }
    k = k - n;      //Reset Counter to the value of the first digit in current row.
    i--;
    j--;
    for (; i > 0; i--)
    {
        j = i;
        elemcount = 0;          //Counter to keep track of elements printed.
        for (; j> 0; j--)
        {
            cout << k << "\t";
            k++;
            elemcount++;
        }
        k = k - elemcount - (i-1); //Resetting K, substracting the number of elements printed and number of elements to be printed in next row.
        cout << endl;
    }

    return 0;
}