mercredi 10 mars 2021

Could you please help me what all am I missing in the logic of the code I am attaching below?

I'm trying to print the following pattern in C++:

        1
      1 2
    1 2 3
  1 2 3 4
1 2 3 4 5
  1 2 3 4
    1 2 3
      1 2
        1
#include <iostream>
using namespace std;

int main() {

   int i, j,k;

   for(i=-4;i<=4;i++)
   {

       for(j=1;j<(2*abs(i)); j++)
        cout<< " ";
       for(k=1; k<6-abs(i);k++)
        cout <<k;

   }
}

I'm having issues with moving to the next line.

Aucun commentaire:

Enregistrer un commentaire