How to get Serial print fibonacci numbers

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.

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

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?

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.

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.

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.

GolamMostafa:
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.

You were requested to get 7 terms (and not the 7th term) on Serial Monitor like this:

smFibo.png

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.

smFibo.png

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…

GolamMostafa:
You requested to get 7 terms (and not the 7th term) on Serial Monitor like this:

smFibo.png

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.

Capture.JPG

Jchandeepa:
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....

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.

PerryBebbington:
I feel sure I’m missing your point buy you seem to have answered your own question…

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.

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...

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.

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. :frowning: :frowning: :frowning:

#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

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.

Have you got the clue of Post#1?

1. Assume the givem number is 12345. Ans: 5.

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.

Jchandeepa

DO NOT CROSS POST.
Your other post was removed.

Please read this before making any further comments

Bob.

Since the BigNumber representation is based on a character array, there may be faster ways to do what you want.

Doing so will require you to study and understand the library code.

Thank you all of you guys gave me the replies.. :slight_smile: :slight_smile:
yes i want to get the how many digit in the value. but i'm trouble with the big number. in my result there are about 40 numbers. i cant convert into int value, can you tell me what's the data type of bignumber result.
result is here:
150th of fibonacci value is : 9969216677189303386214405760200

So how i get the 3rd number(6) value.?? please help me.. :frowning: :frowning: :frowning:

can you tell me what's the data type of bignumber result.

As jremington said

Since the BigNumber representation is based on a character array

From my look at the library, I think that the result is a null terminated character array.

how i get the 3rd number(6) value.??

result[2] will be 6. Note that the array index starts from 0.

as well as the how many digits have this result.

Iterate over the array looking for a match.

int countMatch(char* num, byte position)
{
  int i = 0;
  int count = 0;
  while (num[i] != '\0')
  { 
    if (num[i] == num[position-1])
      count++;
    i++;
  }
  return count;
}


void setup() {
  Serial.begin(115200);
  char * num = "9969216677189303386214405760200";
  Serial.println(num);
  Serial.print("The third number from left is ");
  Serial.println(num[2]);
  Serial.print("The number of matches to third number is ");
  Serial.println(countMatch(num,3));
}

void loop() {}

So how i get the 3rd number(6) value

That would be the third digit from the left. See reply #1 for the completely general method.