Pseudocode assignment no.1 explanation

dear sir,
can u explain me the solution of the assignment no.1 of pseudocode assignment.

hello @Coder19
please post the question here.

Write pseudocode to print the following pattern
1
232
34543
4567654
567898765

@Coder19
you need to observe following things.
a) if i is the row number then it will contain 2*i-1 digits.

b) starting and ending digit of ith row will be i only.
in between it will first increase upto 2*i-1 then start decreasing.

i think these observations are sufficient to code this problem

can u explain me more briefly

what u are not getting

i am not understanding how to increase and then decrease the value in each row…

i mean how to update the value

1
232
34543
4567654
567898765

let consider the third row.

we know row numbe is 3 then it will start from 3 .
also its value will first increase upto 3*2-1 (i.e 5) then decrease to 3 again.
so
3 then 4 then 5 (ok so now we have reached maximum value we will start decreasing now)
4 then 3 (value again become 3 its time to stop row 3 done).
hence the resultant will be 34543

yes i understand this but how i write this part in pseudocode

for row in range 1 to n.

  • value=row

  • while value < 2*row-1

  • -> print value
    
  • -> value=value+1
    
  • while value >=row

  • ->print value
    
  • ->value=value - 1
1 Like

#include
using namespace std;
int main()
{
int n;
cin>>n;
int row=1;
while(row<=n)
{
int value=row;
while(value<=(2*row-1))
{
cout<<value;
value++;
}
value-=2;
while(value>=row)
{
cout<<value;
–value;
}
cout<<endl;

	++row;
}

}