sobota, 18 lutego 2017

Prime numbers transformation (C++ Builder)




private: // User declarations
bool __fastcall is_First(int x);
void __fastcall init_Random();
void __fastcall init_Table();
void __fastcall delete_Table();
int sum_first;
float *first_per_sum,sum_first_per_sum;
float *first_per_next_sum,sum_first_per_next_sum;
float *table_double_sum,sum_double_sum;
float *pow_first_per_next_sum,sum_pow_first;
int *sum_minus_first,sum_minus;
float *next_digit,sum_digit;
float *new_value,sum_new_value;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
int *my_first;


bool __fastcall TForm1::is_First(int x)
{
int i,sum;
sum=0;
for(i=1;i<x+1;i++)
if(x%i==0)
 ++sum;
if(sum==2)
return true;
else
return false;
}
void __fastcall TForm1::init_Random()
{
srand(time(NULL));
}
void __fastcall TForm1::init_Table()
{
my_first=new int[36];
first_per_sum=new float[36];
first_per_next_sum=new float[36];
table_double_sum=new float[36];
pow_first_per_next_sum=new float[36];
sum_minus_first=new int[36];
next_digit=new float[36];
    new_value=new float[36];
sum_first=0;
int i,j;
i=0;j=2;
do
{
if(is_First(j))
{
my_first[i]=j;
sum_first+=j;
++i;
}
++j;

}while(i<36);
sum_first_per_sum=0.;
sum_minus=0;
for(i=0;i<36;i++)
{
 first_per_sum[i]=(1.*my_first[i])/(sum_first*1.);
 sum_first_per_sum+=first_per_sum[i];
 sum_minus_first[i]=sum_first-my_first[i];
 sum_minus+=sum_minus_first[i];


}
next_digit[0]=0.;
sum_digit=0.0;
for(i=1;i<36;i++)
{
next_digit[i]=(1.*sum_minus_first[i])/(1.*sum_minus_first[i-1]);
sum_digit+=next_digit[i];

}
first_per_next_sum[0]=0.;
sum_first_per_next_sum=0.;
sum_pow_first=0.;
sum_double_sum=0.;
for(i=1;i<36;i++)
{
first_per_next_sum[i]=(1.*my_first[i])/(1.*my_first[i-1]);
sum_first_per_next_sum+=first_per_next_sum[i];


}
for(i=0;i<36;i++)
{
table_double_sum[i]=first_per_sum[i]+first_per_next_sum[i];
sum_double_sum+=table_double_sum[i];
pow_first_per_next_sum[i]=first_per_next_sum[i]*first_per_next_sum[i];
sum_pow_first+=pow_first_per_next_sum[i];
}
sum_new_value=0.0;
for(i=0;i<36;i++)
{
new_value[i]=((sum_minus-(my_first[i]*first_per_next_sum[i]*first_per_next_sum[i]))/sum_first);;
sum_new_value+=new_value[i];
}

}
void __fastcall TForm1::delete_Table()
{
delete my_first;
delete first_per_next_sum;
delete table_double_sum;
delete sum_minus_first;
delete next_digit;
delete pow_first_per_next_sum;
delete first_per_sum;
delete new_value;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
 init_Random();
 init_Table();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
 delete_Table();
 Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
 int i;
 for(i=0;i<36;i++)
 {
ListBox1->Items->Add(IntToStr(my_first[i]));
ListBox2->Items->Add(FloatToStr(first_per_sum[i]));
ListBox3->Items->Add(FloatToStr(first_per_next_sum[i]));
ListBox4->Items->Add(FloatToStr(table_double_sum[i]));
ListBox5->Items->Add(FloatToStr(pow_first_per_next_sum[i]));
ListBox6->Items->Add(IntToStr(sum_minus_first[i]));
ListBox7->Items->Add(FloatToStr(next_digit[i]));
ListBox8->Items->Add(FloatToStr(new_value[i]));
 }
 Edit1->Text=IntToStr(sum_first);
 Edit2->Text=FloatToStr(sum_first_per_sum);
 Edit3->Text=FloatToStr(sum_first_per_next_sum);
 Edit4->Text=FloatToStr(sum_double_sum);
 Edit5->Text=FloatToStr(sum_pow_first);
 Edit6->Text=IntToStr(sum_minus);
 Edit7->Text=FloatToStr(sum_digit);
 Edit8->Text=FloatToStr(sum_new_value);
}

Brak komentarzy:

Prześlij komentarz