Psedocode Assignment

sir, i am not able to get the logic to print the pattern. what should be the logic to to write second for loop in the pattern

Hello @chaman9,

If you are taking about the pattern:
1
2 3
4 5 6
7 8 9 10

When you have to print a pattern, always try to find the relationships:
Observations:

  1. first(1) line has 1 element
    second(2) has 2 elements
    third(3) line has 3 elements and so on…

  2. The values you have to print are continuous:
    1 2 3 4 5 6 7 8 9 10
    Take a variable and initialize it to 1 (before the loops)
    after printing it’s current value inside the second loop increment it.

APPROACH:

  1. temp=1;
  2. for i=1 to 4 do
    2.1. for j=1 to i do
    2.1.1. print temp;
    2.1.2. temp=temp+1;
    2.2. end loop
  3. end loop

Now, try to write pseudocode yourself.
Hope, this would help.
Give a like if you are satisfied.

Hey virender actually i am asking for the pattern given in the assignment

Hey @chaman9,

Can you share the pattern.

hey virender, i was talking about this one
1
232
34543
4567654
567898765

So @chaman9, in this case you can deduce the following observations:

  1. first(1) line starts with 1
    the second(2) line starts with 2
    and so on…

  2. each line contain 2*(line no.)-1 elements

  3. increment values the current line no. times
    and then decrement it (line no.-1) times

  4. There are two separate inner loops:
    one for increment purpose and another for decrement

Approach:
for(int i=1;i<=5;i++){
int j;
for(j=i;j<j+i;j++){
cout<<j<<" “;
}
for(j=j-1;j>=i;j--){
cout<<j<<” ";
}
cout<<endl;
}

Try to write a pseudocode

1 Like

Thanks a lot bro i will write it.

Anytime @chaman9,

Please mark it as resolved if you don’t have any doubt regarding this.

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.

Hi @chaman9
Is there still any doubt in how to approach the question,
please elaborate on your query

Thank you for help virender, actually today only i opened coding blocks.
i was travelling back to hometown

1 Like

Anytime @chaman9,

Mark it as resolved now.

already marked it as solved.