50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace Lab
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for FibonacciWindow.xaml
|
|
/// </summary>
|
|
|
|
public partial class FibonacciWindow : Window
|
|
{
|
|
private void ClickBack(object sender, RoutedEventArgs e) => Close();
|
|
|
|
private void ClickCalc(object sender, RoutedEventArgs e)
|
|
{
|
|
OutBox.Text = "";
|
|
InfoText.Text = "";
|
|
|
|
if (!Parsers.TryParseInt(NBox.Text, out int n) || n <= 0) {
|
|
InfoText.Text = "Введите целое N, N > 0.";
|
|
return;
|
|
}
|
|
|
|
long a = 1;
|
|
long b = 1;
|
|
List<long> list = new List<long>();
|
|
while (a < n) { list.Add(a); if (long.MaxValue - a < b) break; long next = a + b; a = b; b = next; }
|
|
|
|
OutBox.Text = string.Join(", ", list);
|
|
InfoText.Text = $"Найдено чисел: {list.Count}.";
|
|
}
|
|
|
|
public FibonacciWindow()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
}
|
|
}
|