100 002
Assignments Done
98.3%
Successfully Done
In June 2021

# Answer to Question #1617 in C# for James

Question #1617
I want to write a code using the fibonacci series. When a user inserts a number it should give the numbers in between the sequence along with an option to conitinue or quit.
1
2011-03-09T04:18:50-0500
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace q1617
{
class Program
{
static int number;
//Get Fibonacci number before and after "int Number"
static int[] fibonacciBetween(int Number)
{
int before = 0;
int after = 1;
do
{
//Example:
//0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,
if (before < Number && Number < after) return new int[] { before, after, 0 }; // it for case when number = 22 (from 21 to 34)

if (before < Number && Number == after) return new int[] { before, before + after, 1 }; // it for case when number = 34 (21 or 34, etc..)
int afterTMP = after;
after = before + after;
before = afterTMP;
} while (true);
}
static void Main(string[] args)
{
Console.Clear();
Console.Write("Enter number: ");

if (number < 1)
{
return;
}

int[] between = fibonacciBetween(number);
Console.WriteLine("Number before: {0}", between[0]);
Console.WriteLine("Number after: {0}", between[1]);
Console.WriteLine("Press space for show next fibonacci number(other key for exit)");
while (key.Key == ConsoleKey.Spacebar)
{
if (between[2] == 1)
{
between[0] = between[1] - between[0];
between[2] = 0;
}
int afterTMP = between[1];
between[1] = between[1] + between[0];
between[0] = afterTMP;
Console.Write(" {0}", between[1]);
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!