Pattern number pyramid

in this code we have to make a pattern no of pyramid like

1
232
34543

but I wrote the code as this

#include

using namespace std;

int main()

{
int n;

int row=1;

cout<<“enter the no of rows”;

cin>>n;

for(;row<=n;)

{
int col=1;

int x=row;

	for(;n-row>0;)
	{
		cout<<" ";
		row=row+1;
	}
	
	for(;col<=row;)
	{
		cout<<x;
		x=x+1;
		col=col+1;
	}
	
	for(;x>1;)
	{
		x=x-1
		cout<<x;
	}
	row=row+1;
	cout<<endl;



}
return 0;

}
but why my output is not correct pls tell

Hey @dhruvk3k share your code using ide.codingblocks.com so that I can help you with your code. If you don’t know how to share, then you can ask me that also :slight_smile:

how to share code please tell me

pls tell me my mistakes

  1. Click this link
    ide.codingblocks.com
  2. Paste your code on this ide which you want me to debug it.
  3. After pasting your code, click on file button on navigation bar and press save button on it.
  4. It will generate an unique url of your code. Share that url with me and I’ll debug it for you :slight_smile:

You haven’t saved it , save it then share the url

Good @dhruvk3k you have figured it out. Now let me debug it for you. Till then be patient :slight_smile:

Hey @dhruvk3k your output is not correct because you are not keeping spaces in your code as the resultant output will be in shape of pyramid. Moreover the logic you have used is also not correct as you are not printing the required numbers
The hint is that if your n is 6
Then in your 6th row, you will print 6 7 8 9 10 11 10 9 8 7 6
That means 2x6-1, 11 columns in which last digit is occupied by 6 number and middle 9 digits are filled by first filling increasing digits and then decreasing digits.
Take this code for reference as it will help you to understand the implementation since I have added few comments too for better understanding


Hope this would help you :slight_smile:

1 Like