check fibonacci

PHOTO EMBED

Thu Oct 14 2021 16:03:44 GMT+0000 (UTC)

Saved by @_Ryan_ #c#

using System;
using System.Collections.Generic;
using System.Linq;
namespace Fibonacci
{
    class Program
    {
        static void Main(string[] args)
        {           
            List<int> number = new List<int>();
            checkInputData(ref number);
            if (checkFibonacci(number))
            Console.WriteLine("is fibonacci sequence");
            else
             Console.WriteLine("is not fibonacci sequence");

        }
        static void checkInputData(ref List<int> number)
        {
            Console.Write("Enter fibonacci sequence: ");
            
            do
            {
                number = Console.ReadLine().Split().Select(int.Parse).ToList();
                if (number[0] != 0 && number[1] != 1 || number[0] != 1 && number[1] != 1 )
                    Console.Write("ERROR! Enter again: ");
            } while (number[0] != 0 && number[1] != 1 || number[0] != 1 && number[1] != 1);
            

        }
        static bool checkFibonacci(List<int> number)
        {
            bool result = true;
            int sum = 0;
            for (int i = 0, j = 2; i < number.Count - 2; i++, j++)
            {
                sum = number[i] + number[i + 1];

                if (number[j] != sum)
                {
                    result = false;
                    break;
                }              
            }

            return result;
        }
    }
}
content_copyCOPY