Generating the febonacci series in C#
class Program
{
static void Main(string[] args)
{
string InuputString = "Febonacci
Series \n";
Console.WriteLine(InuputString);
GenerateFibonacciSeries(10);
}
public static void
GenerateFibonacciSeries(int value)
{
int ftemp = 0;
int f1 = 1;
//temporary variable
int f2 = 0;
Console.Write(f1);
//loop through all the numbers
for (int i = 0; i < value; i++)
{
//assign temporary variable
f2 = ftemp;
ftemp = f1;
f1 = f2 + ftemp;
Console.Write(" ");
Console.Write(f1);
}
}
}
Output :
No comments:
Post a Comment