Patterns numbers and stars-1

on submitting this code ,one test case for negative numbers is not passing out why?

hello @lovely

check ur code for n=8
image

this is not printing correct shape


i have corrected my code but still negative numbers testcase is not passing out .why?

there will no negative input in the test case.

check this->

#include <iostream>
using namespace std;
int main() {
     int i,j,n,k=1;
     cin>>n;
     
      for(i=1;i<=n;i++)
     {    //each row will have
          //n-i+1 numbers;
          for(int j=1;j<=n-i+1;j++)
             cout<<j<<" ";
          // 2*i-3 stars
          for(int j=1;j<=2*i-3;j++)
           cout<<"* ";   

           cout<<"\n";
     }
    return 0;
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.