Skip to content

Instantly share code, notes, and snippets.

@ALiwoto
Created December 2, 2022 13:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ALiwoto/e7d7addccd8687497e8beea31c7eb271 to your computer and use it in GitHub Desktop.
Save ALiwoto/e7d7addccd8687497e8beea31c7eb271 to your computer and use it in GitHub Desktop.
QueraQuestion17675
using System;
namespace CW1
{
public class QueraQuestion17675
{
static int previousFib = 0;
static int lastFib = 1;
public static void Main(string[] args)
{
var theNumber = Convert.ToInt32(Console.ReadLine());
var totalStr = "";
for (int i = 1; i <= theNumber; i++)
{
totalStr += IsFib(i) ? "+" : "-";
}
Console.WriteLine(totalStr);
}
private static bool IsFib(int theNum)
{
if (theNum == lastFib)
return true;
var f0 = previousFib;
var f1 = lastFib;
int f2;
for (int i = f1; i <= theNum; i++)
{
f2 = f1 + f0;
f0 = f1;
f1 = f2;
if (theNum == f1)
return true;
previousFib = lastFib;
lastFib = f2;
if (f1 > theNum)
break;
}
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment