vendredi 27 novembre 2020

Not able to Print the Pattern in c++ [closed]

After executing the code the first half is not getting instead receiving this output: Expecting:

         1
        232
       34543
      4567654

//Above output is not getting

Getting: 1 230 34500 4567000

//Problem in printing the above pattern

void p8(int n){
    int star=1;
    int space=n-1;
    int number;
   
    for (int i = 1; i <= n; i++)
    {
        number=i;

        for (int j = 1; j <= space; j++)
        {
            cout<<" ";   
        }
        for (int j = 0; j < 2*number-1; j++)
        {
           
            if(j<=number/2){

                cout<<i+j;
            }
            else{

                cout<<number-i;
            }

        }

        number+=2;
        space--;

        cout<<endl;
        
    }
}

Aucun commentaire:

Enregistrer un commentaire