Ques. Print the following Pattern and get the output to match test cases?

To print the pattern like
 for n=3
the program should print
1 1 1 2
3 2 2 2
3 3 3 4

Program in C++

#include <iostream>

using namespace std;

int main()
{
   int n=3,c=n-1;
   for(int i=1;i<=n;i++)
   {
       if(i%2==0)
       cout<<c++;
       for(int j=1;j<=n;j++)
       {
           cout<<i;
       }
       if(i%2!=0)
       cout<<c++;
       cout<<“\n”;
   }
  
  
   return 0;
}

Program in C

#include 
int main(void) {
int i,j,n=3,c=n-1;
for(i=1;i<=n;i++)
{
if(i%2==0)
printf(“%d”,c++);
for(j=1;j<=n;j++)
{
printf(“%d”,i);
}
if(i%2!=0)
printf(“%d”,c++);
printf(“\n”);
}

return 0;
}