Go Down

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

ballscrewbob

#15
Sep 18, 2019, 06:22 pm Last Edit: Sep 18, 2019, 06:23 pm by ballscrewbob
Jchandeepa

DO NOT CROSS POST.
Your other post was removed.

Please read this before making any further comments

Bob.
It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

jremington

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.

Jchandeepa

Thank you all of you guys gave me the replies..  :)  :)
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:
150
Code: [Select]
th of fibonacci value is : 9969216677189303386214405760200

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


cattledog

Quote
can you tell me what's the data type of bignumber result.
As jremington said
Quote
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.

Quote
how i get the 3rd number(6) value.??
result[2] will be 6. Note that the array index starts from 0.

Quote
as well as the how many digits have this result.
Iterate over the array looking for a match.

Code: [Select]
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() {}

jremington

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

ballscrewbob

Last topic MERGE...

Timeouts from here on.

Bob.


It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

Go Up