С++ Builder 6 Числа фибоначчи рекурсия
Компиляция и сборка под Windows 10
Как мы видим 48 чисел высчитывает за шесть минут
Исходник и исполняемый файл здесь
Кто запустит отпишитесь в коментах работает ли
под Windows 7: 8: XP
=
=
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//----------------------------------------------
float __fastcall TForm1::fibonacci(int N) // рекурсивная функция
{
if (N == 1 || N == 2)
return 1; // первые 2 числа равны 1
return fibonacci(N - 1) + fibonacci(N - 2); // складываем предыдущие 2 числа
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TDateTime t1, t2;
t1 = Time();
ListBox1->Items->Clear();
N++;
Edit1->Text = N;
for (int i = 1; i <= N; i++) {
ListBox1->Items->Add(IntToStr(i) + "---" + FloatToStr( fibonacci(i) ) ) ;
}
t2 = Time();
AnsiString s;
DateTimeToString( s , "hh:nn:ss:zzz" , t2 - t1 );
ListBox2->Items->Add( IntToStr( N) + "----" + s );
}
//--------------------В Edit1 только цифры-------------------------------------------------------
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
if(Key >= '0' && Key <= '9' || Key == VK_BACK ) return;
Key = 0;
}
//------------------Сброс---------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Edit1->Text = "1";
ListBox1->Items->Clear();
ListBox2->Items->Clear();
N = 0;
}
//---------------------------------------------------------------------------
=
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TEdit *Edit1;
TButton *Button1;
TListBox *ListBox1;
TLabel *Label2;
TListBox *ListBox2;
TButton *Button2;
TLabel *Label1;
TLabel *Label3;
TBevel *Bevel1;
TBevel *Bevel2;
TLabel *Label4;
void __fastcall Button1Click(TObject *Sender);
void __fastcall Edit1KeyPress(TObject *Sender, char &Key);
void __fastcall Button2Click(TObject *Sender);
private: // User declarations
public: // User declarations
int N;
float __fastcall fibonacci(int N); // рекурсивная функция
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
=
=
|