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;

 
 
 
 




 


}
};
}

Brak komentarzy:

Prześlij komentarz