piątek, 23 września 2016

Relations on first numbers in Visaul C++



#pragma endregion
private: System::Void init_Random()
{
srand(time(NULL));
}
private: System::Boolean 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;
}
private: System::Void write_Table(int *table, int size)
 {
                int i,j;
i=0;j=1;
do
{
if(is_First(j))
{
table[i]=j;
++i;
}
++j;
}while(i<size+1);
 }
 private: System::Int32 howmany_Elements(int x)
  {
  int i,sum;
  i=1,sum=1;
  do
  {
  
  if(is_First(i))
  {
  ++sum;
  
  }
  ++i;

  }while(i!=x);
  return sum;

  }
 private: System::Int32 sum_Table(int *table, int size)
  {
  int i,sum;
  sum=0;
  for(i=0;i<size;i++)
  sum+=table[i];
      return sum;
  }
  private: System::Int32 random_First()
{
int x,i,max;
max=1000;
x=rand()%max+2;
if(!is_First(x))
{   i=x;
do
{
++i;
}while(!is_First(i));
return i;
}
else
return x;
}
  private: int *table;
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) { 
Close();
}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
int x,how_many_in_table,sum,i;
x=random_First();
textBox1->Text=x.ToString();
how_many_in_table=howmany_Elements(x);
textBox2->Text=how_many_in_table.ToString();
table=new int[how_many_in_table];
listBox1->Items->Clear();
write_Table(table,how_many_in_table);
sum=sum_Table(table,how_many_in_table);
textBox3->Text=sum.ToString();
for(i=0;i<how_many_in_table;i++)
listBox1->Items->Add(table[i].ToString());
double sqrt_table;
sqrt_table=sqrt(1.0*sum);
textBox4->Text=sqrt_table.ToString();
double value_per_sum;
value_per_sum=(1.0*x+how_many_in_table)/(sum*1.0);
textBox5->Text=value_per_sum.ToString();
double value_mal_sum;
value_mal_sum=(1.0*x*how_many_in_table)/(sum*1.0);
textBox6->Text=value_mal_sum.ToString();
double sqrt_another_sum;
sqrt_another_sum=sqrt(1.0*(x+sum+how_many_in_table));
textBox7->Text=sqrt_another_sum.ToString();
delete table;
 
}
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
init_Random();
}
};
}

Brak komentarzy:

Prześlij komentarz