Computer Science, asked by BrainlyProgrammer, 4 months ago

New Question!!
WAP to print the following pattern:-

0 1 1 2 3
1 1 2 3 5
1 2 3 5 8
2 3 5 8 13
2 5 8 13 21​


BrainlyProgrammer: there is a mistake in the last line of the pattern... it should be 3 5 8 13 21
BrainlyProgrammer: Programming language accepted:- Java,Python, Qbasic

Answers

Answered by pro12348
0

Answer: steal something from your neighbour, and wait him/her to realize that and tell him/her to return your pens and after he/she returns your pens then give that item to your neighbour that you stolen . simple?

Explanation: sory but i don't know

Answered by allysia
4

Language:

Python

Program:

Consider the attachment.

Output:

Consider the attachment.

Explanation:

  • Line 367: Asks for user input for the number of rows required (the column is fixed to length of 5 as in the pattern mentioned).
  • Line 372: Defines an empty list.
  • Line 373: Uses for loop to generate Fibonacci's sequence,  z is initialized at -1 and b is at 1, ow every time the loop runs z's value changes to the sum of z and b, and similarly, b's value changes to z+b, to understand why I did this  consider the explanation I have added on Fibonacci's sequence below.
  • Line 376 and 377: Attach these changing values to end of the list every time the loop runs,
  • Line 381: Uses while loop to change the initial value of for loop to make sure every time this loop runs the elements accessed are at one index more than before. The final range limit is 5+i to make sure only 5 elements get printed in each line.
  • Line 383: end=" " makes sure that the elements are printed in same line separated by a " "  (space)
  • Line 385: print() adds new line evetime for loop ends.

Fibonacci's sequence:

This sequence goes like:

0,1,1,2,3,5,8,13,21,34 and so one.

It begins with 0 and 1 and every other element followed are sum of previous 2.

Extra: It is special because biology seems to follow it. You can notice it in nature the many flower petals , their seeds follow this sequence.

Attachments:

BrainlyProgrammer: Great Explaination!! Correct Output!! Best Answer!!
BrainlyProgrammer: Keep it up!!!
anindyaadhikari13: Without using arrays?
allysia: tqsm.
Similar questions