How to print Fibonacci series upto -nth term | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

How to print Fibonacci series upto -nth term

https://code.sololearn.com/cFjTZ9ZZHrum/?ref=app

6th Nov 2022, 8:51 PM
Ashok Kumar V
Ashok Kumar  V - avatar
12 ответов
+ 2
Thanks, SoloProg! My question was for a negative number ex: if input is equal 8 then fibbonaci series should be printed till 8 not more than 8 . Hope you understood Could you please check provide a solution if possible
7th Nov 2022, 3:46 AM
Ashok Kumar V
Ashok Kumar  V - avatar
+ 2
Ashok Kumar V , Hope this helps Fibonacci Series using Recursion Positive and negative numbers https://www.sololearn.com/compiler-playground/cMeUZON38E5o
8th Nov 2022, 8:55 PM
SoloProg
SoloProg - avatar
+ 1
Ashok Kumar V , Hope this helps Fibonacci Series using Recursion int fib(int n) { if (n <= 1) return n; return fib(n-1) + fib(n-2); } https://www.sololearn.com/compiler-playground/cMBrriF5zsU8
6th Nov 2022, 11:03 PM
SoloProg
SoloProg - avatar
+ 1
You want to print only negative number? like if you input the number 8 then fibonacci series print -1 to -8 like this.
7th Nov 2022, 5:25 AM
Sakshi
Sakshi - avatar
+ 1
My input is negative number
8th Nov 2022, 6:02 PM
Ashok Kumar V
Ashok Kumar  V - avatar
+ 1
Ashok Kumar V you can't take input directly in negative number.
8th Nov 2022, 6:21 PM
Sakshi
Sakshi - avatar
+ 1
Sakshi see my above code
8th Nov 2022, 6:23 PM
Ashok Kumar V
Ashok Kumar  V - avatar
+ 1
In while condition after that you write c = a - b; then it subtract the value.
8th Nov 2022, 6:25 PM
Sakshi
Sakshi - avatar
+ 1
Your main question is how to input the negative value then it's not possible, you can store the value in positive or negative way instead of input.
8th Nov 2022, 6:27 PM
Sakshi
Sakshi - avatar
+ 1
I hope it's clear to you
8th Nov 2022, 6:28 PM
Sakshi
Sakshi - avatar
+ 1
Okay thanks
8th Nov 2022, 6:28 PM
Ashok Kumar V
Ashok Kumar  V - avatar
+ 1
Thanks! Soloprog
8th Nov 2022, 8:56 PM
Ashok Kumar V
Ashok Kumar  V - avatar