Go Down

### Topic: How to get Serial print fibonacci numbers (Read 262 times)previous topic - next topic

#### Jchandeepa

##### Sep 17, 2019, 05:54 pm
I want to get the vale of 150th fibonacci number into an array.

ex :

150th fibonacci vale is = 9969216677189303386214405760200
I want to input into an array like this,

int myArray[]={9,9,6,9,2,1,6,6,7,7,1,8,9,3,0,3,3,8,6,2,1,4,4,0,5,7,6,0,2,0,0};

#### TheMemberFormerlyKnownAsAWOL

#1
##### Sep 17, 2019, 06:06 pm
Chose an integer data type with at least 103 binary digits.

#### GolamMostafa

#2
##### Sep 17, 2019, 06:21 pmLast Edit: Sep 17, 2019, 06:24 pm by GolamMostafa
You show us first with an Arduino sketch how you are going to get the 150th term of the Fibonacci number sequence? Is it 9969216677189303386214405760200 what you said or it is: 6161314747715278029583501626149?

#### Jchandeepa

#3
##### Sep 17, 2019, 07:02 pm
actually In here 9969216677189303386214405760200 value i got from by using online calculator.
but i want to get the value of 150th fobonacci value using arduino.

#### GolamMostafa

#4
##### Sep 17, 2019, 07:10 pm
actually In here 9969216677189303386214405760200 value i got from by using online calculator.
but i want to get the value of 150th fobonacci value using arduino.
Ok!

Post a simple sketch to find 7 Fibonacci terms. Search Google, get a C program, upload it in the UNO, show the terms in the Serial Monitor, and post the screenshot of the Serial Monitor.

#### Jchandeepa

#5
##### Sep 17, 2019, 07:28 pm
Ok!

Post a simple sketch to find 7 Fibonacci terms. Search Google, get a C program, upload it in the UNO, show the terms in the Serial Monitor, and post the screenshot of the Serial Monitor.
Here is the screenshot of the 7th fibonacci number. thank you.

#### GolamMostafa

#6
##### Sep 17, 2019, 07:39 pmLast Edit: Sep 18, 2019, 06:07 am by GolamMostafa
You were requested to get 7 terms (and not the 7th term) on Serial Monitor like this:

What are the terms in a Fibonacci number sequence?
Ans: Excluding the first two terms, the next term is always equal to the sum of the just preceding two terms.

Use the above principle and write your simple C codes without using recursion.

#### septillion

#7
##### Sep 17, 2019, 07:40 pm
Really, a screen shot....

But like @ TheMemberFormerlyKnownAsAWOL mentioned, your (first) biggest problem is finding a datatype that actually can hold that number. You need at least 103 bits to do so and that's not really a trivial size, especially in microcontroller land.

And small calculation:
103 bit = 13 bytes
150 items => 13 bytes x 150 = 1950  bytes
That's as good as ALL the RAM an Uno has...
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake

#### Jchandeepa

#8
##### Sep 17, 2019, 07:53 pm
You requested to get 7 terms (and not the 7th term) on Serial Monitor like this:

What are the terms in a Fibonacci number sequence?
Ans: Excluding the first two terms, the next term is always equal to the sum of the just preceding two terms.

Use the above principle and write your simple C codes without using recursion.
Simply i want to do this. but i don't know how to do in arduino. because there is no such long data type. here i attached a screenshot. i got if from the online calculator.

#### PerryBebbington

#9
##### Sep 17, 2019, 07:57 pm
I want to input into an array like this,

int myArray[]={9,9,6,9,2,1,6,6,7,7,1,8,9,3,0,3,3,8,6,2,1,4,4,0,5,7,6,0,2,0,0};

How i do this.?

Code: [Select]
`int myArray[]={9,9,6,9,2,1,6,6,7,7,1,8,9,3,0,3,3,8,6,2,1,4,4,0,5,7,6,0,2,0,0};`
How does that not do what you want?

Then just use serial.Print inside a for() loop to print each element to the serial port. If that's not what you meant the I don't know what you do mean, sorry.

#### Jchandeepa

#10
##### Sep 17, 2019, 08:02 pm

Code: [Select]
`int myArray[]={9,9,6,9,2,1,6,6,7,7,1,8,9,3,0,3,3,8,6,2,1,4,4,0,5,7,6,0,2,0,0};`
How does that not do what you want?

Then just use serial.Print inside a for() loop to print each element to the serial port. If that's not what you meant the I don't know what you do mean, sorry.

actually here i use only for the example of 150th fibonacci number value (9969216677189303386214405760200). only for the example. in my project the value is more than 150th of fibonacci. thank you.

#### Jchandeepa

#11
##### Sep 17, 2019, 08:08 pm
Really, a screen shot....

But like @ TheMemberFormerlyKnownAsAWOL mentioned, your (first) biggest problem is finding a datatype that actually can hold that number. You need at least 103 bits to do so and that's not really a trivial size, especially in microcontroller land.

And small calculation:
103 bit = 13 bytes
150 items => 13 bytes x 150 = 1950  bytes
That's as good as ALL the RAM an Uno has...
I can't clear what y said. so please can you give me some examples for it. any kind of codes do you have?? thank you.

#### Jchandeepa

#12
##### Sep 18, 2019, 12:28 pm
hi.. please help me. i'm using this code to get the fibonacci value in selected number. it's work.
But i want to get the value of 4th digit in result in the left side, as well as the how many digits have this result.

Code: [Select]
`#include "BigNumber.h"// function to display a big number and free it afterwardsvoid printBignum (BigNumber & n){  char * s = n.toString ();  Serial.println (s);  free (s);}  // end of printBignumvoid setup(){  Serial.begin(9600);  BigNumber::begin ();  // initialize library    int x = 150; // change here    int n = 2;  BigNumber a = 0;  BigNumber b = 1;  BigNumber result;  while (n <= x) // while value do you want  {    result = a + b;    n++;    a = b;    b = result;  }  // end of while  Serial.print (x);  Serial.print (" = ");  printBignum (result);} // end of setupvoid loop(){}  // end of loop`

#### jremington

#13
##### Sep 18, 2019, 03:45 pmLast Edit: Sep 18, 2019, 03:47 pm by jremington
To determine how many decimal digits (N) there are in an integer number, count the number of times you can do an integer divide by ten, stopping when the result is zero.

To get the fourth digit from the left (assuming that the number is larger than 999), get the number of digits N as above, then start with the original number and repeat the divide-by-ten process N-3 times. Divide once more by ten and take the remainder.

#### GolamMostafa

#14
##### Sep 18, 2019, 05:27 pmLast Edit: Sep 18, 2019, 05:28 pm by GolamMostafa
Have you got the clue of Post#1?

1. Assume the givem number is 12345. Ans: 5.
Code: [Select]
`unsigned int x = 12345;void setup() {  Serial.begin(9600);    byte counter=0;  do  {    x = x/10;     counter++;   }  while(x !=0);  Serial.print(counter); //shows: 5}void loop() {  }`

2. Assume the given number is: 98765. Ans: The forth digit from left is 6.
This is  Op's job to devise the sketch.

Go Up