Slight error in code

in the Nth line i am getting two zeros i tried correcting it but am getting an extra digit on the line.

Be patient, let me debug your code. I’ll let you know your mistake

the error due to which your code is giving an extra line is because of this condition

if(j>(2*N-k) and j<=2*N)
         {
              cout<<++temp<<" ";
         }

tell me your approach so that i can debug it for you.

basically i made a variable k which keep increasing till N then it decreases till 2N
and all the numbers and spaces are given the range using this variable for eg the first half of numbers i gave the range 0 to k

for the spaces in between i gave the range k to 2N-k

and for the next half of numbers i gave from 2N-k to 2N

temp is a variable that is assigned to N is being printed for the first half im doing temp-- and then for the next have of numbers im doing ++temp

the only problem is in the nth line im getting 0 twice somehow i need to eliminate 1 of the zeros

Since there was only one issue i.e., when your i was equal to N, i added one condition outside for loop of j and have printed desired output.
The Code for that is here


Although if you don’t want to do it like this you can also take reference from this code too

1 Like