how do I solve this pattern? I'm able to do the left half, but can't think of the right logic for the right half. Anyone wants to help?

1 2 3 4 5 26 27 28 29 30
6 7 8 9 22 23 24 25
10 11 12 19 20 21
13 14 17 18
15 16

Here’s the code I wrote but the right half isn’t the expected oucome…

#include<stdio.h>
int main()
{
    int x=1,y=30,n=10,r,s,c;
    for(r=1;r<=n;r++)
    {
        for(s=2;s<=r;s++)
        {printf(" ");}
        for(c=5;c>=r;c--)
        {printf("%d\t",x);
            x++;}
          for(s=2;s<=r;s++)
        {printf(" ");}
        for(c=5;c>=r;c--)
        {printf("%d\t",y);
            y--;}
        printf("\n");
    }
}

you should calculate what is the number of numbers below any level, int this case it’s (n*(n+1)) and then after reaching the end of current counter you should add that much to your current value .

1 Like

#include
using namespace std;
int R=1,i,j;
int main()
{
for(i=0;i<5;i++)
{
for(j=0;j<i;j++)
{
cout<<" “;
}
for(int k=0;k<5-i;k++)
{
cout<<” “<<R<<” “;
R++;
}
int P=R-2;
for(int l=0;l<5-i;l++)
{
cout<<” “<<30-P<<” ";
P–;
}

        cout<<"\n";
}

}

//Hey ! try my code this will work and please adjust spaces if u want in that code :)…

//