Pattern double side arrow

sir my program can run for 7 but cant run for any other values
can you tell me how can i make my code i generalized for every value …
#include
using namespace std;

int main()
{
int n;
cin>>n;
int value;
//case 1
for(int i=1;i<=n;i++)
{
if(i<=n-3)
{
value=i;
for(int j=1;j<=(n+1)-2i;j++)
{
cout<<" “;
}
for(int k=1;k<=i;k++)
{
cout<<value<<” ";
value=value-1;
}
for(int l=1;l<=2
(i-1)-1;l++)
{
if(i<=1)
{
break;
}
else{
cout<<" “;
}
}
int x=1;
for(int m=1;m<=i;m++)
{
if(i<=1)
{
break;
}
cout<<x<<” “;
x=x+1;
}
}
else
{
int value=(n+1)-i;
for(int f=1;f<=-(n+1)+2i;f++)
{
cout<<" “;
}
for(int g=1;g<=(n+1)-i;g++)
{
cout<<value<<” ";
value=value-1;
}
for(int y=1;y<=(n+6)-2
i;y++)
{
if(i==n)
{
break;
}
cout<<” “;
}
int e=1;
for(int q=1;q<=(n+1)-i;q++)
{
if(i==n)
{
break;
}
cout<<e<<” ";
e=e+1;
}
}
cout<<endl;
}
return 0;
}

@YASHMATHURIA123 to find a generalised algorithm, try to find a relation between n, i (number of line) and the number or nature of characters to be printed. Then the next thing is to verify the relation for various values, to check if it is correct or not. Bhaiya has explained in the lectures how to find those relations, try doing it once with pen and paper. Let me know if you are stuck anywhere!

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.

1 Like