Answers for "c# fibonacci sequence"

C#
6

c# fibonacci sequence

using System;

class Program
{
    public static int Fibonacci(int n)
    {
        int a = 0;
        int b = 1;
        // In N steps compute Fibonacci sequence iteratively.
        for (int i = 0; i < n; i++)
        {
            int temp = a;
            a = b;
            b = temp + b;
        }
        return a;
    }

    static void Main()
    {
        for (int i = 0; i < 15; i++)
        {
            Console.WriteLine(Fibonacci(i));
        }
    }
}
Posted by: Guest on March-23-2020
0

c# fibonacci sequence

class program
{
	static void Fib(int f)
	{
		int a = 0;
		int b = 1;

		if (f >= 0)
			Console.Write(a + ", ");
		if (f >= 1)
			Console.Write(b + ", ");

		for (int i = 2; i <= f; i++)
		{
			Console.Write(a + b + ", ");
			b = a + b;
			a = b - a;
		}
	}

	static void Main(string[] args)
	{
		Fib(7);
	}
}
Posted by: Guest on October-06-2021

C# Answers by Framework

Browse Popular Code Answers by Language