Created
December 2, 2022 13:15
-
-
Save ALiwoto/e7d7addccd8687497e8beea31c7eb271 to your computer and use it in GitHub Desktop.
QueraQuestion17675
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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