Go Down

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

Jchandeepa

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};

How i do this.? please help me.


 

TheMemberFormerlyKnownAsAWOL

Chose an integer data type with at least 103 binary digits.

GolamMostafa

#2
Sep 17, 2019, 06:21 pm Last 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

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.
and that value input to the array. please help me. 

GolamMostafa

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.
and that value input to the array. please help me. 
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

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 pm Last 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

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
https://github.com/septillion-git/FadeLed

Jchandeepa

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

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.?
I feel sure I'm missing your point buy you seem to have answered your own question....


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

I feel sure I'm missing your point buy you seem to have answered your own question....


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

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

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.
please help me.  :(  :(  :(

Code: [Select]

#include "BigNumber.h"

// function to display a big number and free it afterwards
void printBignum (BigNumber & n)
{
  char * s = n.toString ();
  Serial.println (s);
  free (s);
}  // end of printBignum

void 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 setup

void loop()
{

}  // end of loop

jremington

#13
Sep 18, 2019, 03:45 pm Last 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 pm Last 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