Pattern Mountain.Last line remaining subpart is not printing.Y?
Hello @dbhavanishankar89,
There are multiple issues with your program:
-
The logic you have applied for space would not work for other values. Try for 5
spcCount=N+1; This is wrong.
Rather use spcCount=2*(n-1) -1; and decrement it by 2 for each successive iterations. -
Each number is separated from other by a tab.
-
Now, coming back to the problem you have specified:
for 4th row, after executing the first for loop i.e. 1234
Your code is entering the infinite loop, printing space(" “)
In the start of third row, itrCount=1
Then after executing itrCount=itrCount-2, the itrCount becomes -1.
Thus, at the start 4th row spcCount=itrCount=-1;
Hence, the program will stuck into the following while loop, as spcCount will never become 0.
while(spcCount–){
cout<<” ";
} -
You should also consider the case that in last row the element in the middle is printed only once.
Hope,This would help.
Give a like, if you are satisfied.