wtorek, 27 września 2016

First numbers in dataGridView (Visual C++)



#pragma endregion
#define a 10
#define b 40
#define c 100
int *tab_first;
int *between_value,*between_value2;
int *rows_value;

private: System::Boolean  first_Number(int x)
{
int i,sum;
sum=0;
for(i=1;i<x+a;i++)
if(x%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}

private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {

tab_first=new int[c];
between_value=new int[c];
rows_value=new int[c];
between_value2=new int[c];
dataGridView1->ColumnCount=a;
dataGridView1->RowCount=a;
dataGridView2->ColumnCount=a;
dataGridView2->RowCount=a;
dataGridView3->ColumnCount=a;
dataGridView3->RowCount=a;
dataGridView4->ColumnCount=a;
dataGridView4->RowCount=a;
int i,j,k,sum;
for(i=0;i<a;i++)
{
dataGridView1->Columns[i]->Width=b;
dataGridView1->Rows[i]->Height=b/2;
dataGridView2->Columns[i]->Width=b;
dataGridView2->Rows[i]->Height=b/2;
dataGridView3->Columns[i]->Width=b;
dataGridView3->Rows[i]->Height=b/2;
dataGridView4->Columns[i]->Width=b;
dataGridView4->Rows[i]->Height=b/2;

}
i=0;
j=1;
do
{
if(first_Number(j))
{
                       tab_first[i]=j;
  ++i;
}
++j;

}while(i<c);
 
 
i=0;
do
{
j=tab_first[i];
sum=0;
do
{
                   ++sum;
  

}while(j+sum<tab_first[i+1]);
between_value[i]=sum;
               ++i;
 
}while(i<c);

}
 
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
delete between_value2;
delete rows_value;
delete between_value;
delete tab_first;
Close();
}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
int i,j,k,temp_table[a][a],temp_table2[a][a];
k=0;
for(i=0;i<a;i++)
{
for(j=0;j<a;j++)
{
dataGridView1->Rows[i]->Cells[j]->Value=tab_first[k].ToString();
dataGridView2->Rows[i]->Cells[j]->Value=between_value[k].ToString();
temp_table[i][j]=tab_first[k];
++k;
}
}
             k=0;
for(i=0;i<a;i++)
{
for(j=0;j<a;j++)
{
temp_table2[i][j]=temp_table[j][i];
dataGridView3->Rows[i]->Cells[j]->Value=temp_table2[i][j].ToString();
rows_value[k]=temp_table2[i][j];
}
}
System::Int32 x;
System::Int32 y;
for(i=0;i<a;i++)
{
for(j=0;j<a;j++)
{
x=Int32::Parse(dataGridView1->Rows[i]->Cells[j]->Value->ToString());
y=Int16::Parse(dataGridView3->Rows[i]->Cells[j]->Value->ToString());
if(x==y)
dataGridView4->Rows[i]->Cells[j]->Value="1";
else
dataGridView4->Rows[i]->Cells[j]->Value="0";
}
}
int *table_value1,*table_value2;
table_value1=new int[a];
table_value2=new int[a];
            for(i=0;i<a;i++)
{
for(k=0;k<a;k++)
{
if(i==k)
{
table_value1[i]=Int32::Parse(dataGridView1->Rows[i]->Cells[k]->Value->ToString());
table_value2[i]=Int32::Parse(dataGridView2->Rows[i]->Cells[k]->Value->ToString());
listBox1->Items->Add((i+1).ToString()+") "+table_value1[i].ToString()+"-----"+table_value2[i].ToString());
}
}
}
    

delete table_value2;
delete table_value1;

 
 
 
 




 


}
};
}

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();
}
};
}

niedziela, 4 września 2016

Graphics^ in Visual C++

I wanted to recall the graphics methods in Visual C++.



#pragma endregion
private:
System::Void init_Random()
{
srand(time(NULL));
}
private:
Graphics^ my_graph;
Pen^ my_pen1;
Pen^ my_pen2;
Pen^ my_pen3;
Pen^ my_pen4;
Pen^ my_pen5;
Pen^ my_pen6;
private:
System::Drawing::Color color1;
System::Drawing::Color color2;
System::Drawing::Color color3;
System::Drawing::Color color4;
System::Drawing::Color color5;
System::Drawing::Color color6;
private:
System::Void init_Graph()
{
my_graph=panel1->CreateGraphics();
color1=System::Drawing::Color::Yellow;
color2=System::Drawing::Color::Blue;
color3=System::Drawing::Color::Red;
color4=System::Drawing::Color::White;
color5=System::Drawing::Color::Violet;
color6=System::Drawing::Color::Green;
my_pen1=gcnew Pen(color1);
my_pen2=gcnew Pen(color2);
my_pen3=gcnew Pen(color3);
my_pen4=gcnew Pen(color4);
my_pen5=gcnew Pen(color5);
my_pen6=gcnew Pen(color6);


}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
Close();
}
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
init_Graph();
init_Random();
}
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
int centr_x,centr_y,marg=5,i,j;
centr_x=panel1->Width/2;
centr_y=panel1->Height/2;
//frame
my_pen1->Width=3;
my_pen1->DashStyle=System::Drawing::Drawing2D::DashStyle::DashDot;
my_graph->DrawLine(my_pen1,marg,marg,panel1->Width-marg,marg);
my_graph->DrawLine(my_pen1,marg,panel1->Height-marg,panel1->Width-marg,panel1->Height-marg);
my_graph->DrawLine(my_pen1,marg,marg,marg,panel1->Height-marg);
my_graph->DrawLine(my_pen1,panel1->Width-marg,marg,panel1->Width-marg,panel1->Height-marg);
my_pen2->Width=2;
my_pen2->StartCap=System::Drawing::Drawing2D::LineCap::Square;
my_pen2->EndCap=System::Drawing::Drawing2D::LineCap::Round;
my_graph->DrawLine(my_pen2,centr_x,marg,centr_x,panel1->Height-marg);
my_graph->DrawLine(my_pen2,marg,centr_y,panel1->Width-marg,centr_y);
my_pen3->Width=3;
j=30;
    for(i=0;i<4;i++)
{
  my_graph->DrawEllipse(my_pen3,centr_x-j,centr_y-j,j*2,j*2);
  j+=30;
}
Bitmap^ my_bitmap=gcnew Bitmap(panel1->Width,panel1->Height);
System::Drawing::Color temp_color;
for(i=marg;i<panel1->Width-marg;i+=marg)
{
for(j=marg;j<panel1->Height;j+=marg)
{
temp_color=System::Drawing::Color::FromArgb(rand()%255,rand()%255,rand()%255);
my_bitmap->SetPixel(i,j,temp_color);
}
}
my_graph->DrawImage(dynamic_cast<Image^>(my_bitmap),1,1);
my_pen4->Width=5;
my_pen4->StartCap=System::Drawing::Drawing2D::LineCap::RoundAnchor;
my_pen4->EndCap=System::Drawing::Drawing2D::LineCap::ArrowAnchor;
my_pen4->DashStyle=System::Drawing::Drawing2D::DashStyle::DashDot;
my_graph->DrawLine(my_pen4,centr_x,marg,panel1->Width-marg,centr_y);
my_graph->DrawLine(my_pen4,panel1->Width-marg,centr_y,centr_x,panel1->Height-marg);
my_graph->DrawLine(my_pen4,centr_x,panel1->Height-marg,marg,centr_y);
my_graph->DrawLine(my_pen4,marg,centr_y,centr_x,marg);

int x,y,a,h;
x=30,y=30,a=60,h=60;
my_pen5->Width=3;
my_graph->DrawEllipse(my_pen5,x,y,a,h);
x=30,y=panel1->Height-90;
my_graph->DrawEllipse(my_pen5,x,y,a,h);
x=panel1->Width-90,y=30,a=60,h=60;
my_graph->DrawEllipse(my_pen5,x,y,a,h);
y=panel1->Height-90;
my_graph->DrawEllipse(my_pen5,x,y,a,h);
my_pen6->Width=4;
my_pen6->DashCap=System::Drawing::Drawing2D::DashCap::Round;
my_pen6->DashStyle=System::Drawing::Drawing2D::DashStyle::DashDotDot;
my_graph->DrawLine(my_pen6,marg,marg,panel1->Width-marg,panel1->Height-marg);
my_graph->DrawLine(my_pen6,panel1->Width-marg,marg,marg,panel1->Height-marg);


}
};
}

sobota, 3 września 2016

continue first numbers and tables



#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;

#define max 500

int sum_table(int *tab, int size)
{
    int i,sum;
    sum=0;
    for(i=0;i<size;i++)
     sum+=tab[i];
    return sum;
}
bool 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 change_table(int *tab1, int *tab2, int size)
{
    int *temp;
    temp=new int[size];
    int i;
    for(i=0;i<size;i++)
     {
         temp[i]=tab1[i];
         tab1[i]=tab2[i];
         tab2[i]=temp[i];
     }
   
    delete temp;
}
int *first_table;
int main(int argc, char **argv)
{
    int i,j,k,sum;
   
   
    srand(time(NULL));
    first_table=new int[max];
    i=0;j=1;
    do
    {
        if(is_first(j))
        {
            first_table[i]=j;
            ++i;
        }
        ++j;
    }while(i<max);
    int table_testing[max][max],double_first[max][max],f_value[max][max];
    int g_value[max][max],h_value[max],i_value[max][max];
    for(i=0;i<max;i++)
    {
     for(j=0;j<max;j++)
     {
      k=rand()%max;   
      table_testing[i][j]=first_table[k];
      double_first[i][j]=first_table[j];
      if(double_first[i][j]>=table_testing[i][j])
       f_value[i][j]=double_first[i][j]-table_testing[i][j];
      else
       f_value[i][j]=table_testing[i][j]-double_first[i][j];
      if(is_first(f_value[i][j]))
      {
       g_value[i][j]=1;
       i_value[i][j]=0;
      }
      else
      {
       g_value[i][j]=0;
       i_value[i][j]=1;
      }
     }
    }
    for(i=0;i<max;i++)
    {
        for(j=0;j<max;j++)
        {
            h_value[i]=sum_table(g_value[i],max);
            h_value[i]+=sum_table(i_value[i],max);
        }
    }
    for(i=0;i<max;i++)
    {
        for(j=0;j<h_value[i];j++)
        {
            change_table(double_first[j],table_testing[j],h_value[i]);
        }
    }
   

    delete first_table;
    return 0;
}