private: // User declarations
bool __fastcall is_First(int value);
int main_Array[10][10];
int temp_Array[100];
int total_Vertical[10],total_Horizontal[10],difference_Vertical[10],
difference_Horizontal[10];
int A,B,C,D;
void __fastcall init_Array();
bool __fastcall TForm1::is_First(int value)
{
int i,sum;
sum=0;
for(i=1;i<value+1;i++)
if(value%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}
void __fastcall TForm1::init_Array()
{
int i,j,k,sum,difference;
i=0;
j=2;
do
{
if(is_First(j))
{
temp_Array[i]=j;
++i;
}
++j;
}while(i<100);
k=0;
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
main_Array[i][j]=temp_Array[k];
++k;
}
}
i=0;
do
{
sum=0,k=9,difference=main_Array[i][k];
for(j=0;j<10;j++)
{
sum+=main_Array[i][j];
difference-=main_Array[i][k-j];
}
total_Vertical[i]=sum;
difference_Vertical[i]=difference;
++i;
}while(i<10);
i=0;
do
{
sum=0,k=9,difference=main_Array[k][i];
for(j=0;j<10;j++)
{
sum+=main_Array[j][i];
difference-=main_Array[k-j][i];
}
total_Horizontal[i]=sum;
difference_Horizontal[i]=difference;
++i;
}while(i<10);
A=B=0;
C=main_Array[9][9];
D=main_Array[0][9];
for(i=0;i<10;i++)
{
A+=main_Array[i][i];
B+=main_Array[i][9-i];
C-=main_Array[9-i][9-i];
D-=main_Array[i][9-i];
}
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
init_Array();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i,j;
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
StringGrid1->Cells[i][j]=IntToStr(main_Array[j][i]);
}
}
for(i=0;i<10;i++)
{
StringGrid5->Cells[0][i]=IntToStr(total_Vertical[i]);
StringGrid4->Cells[0][i]=IntToStr(difference_Vertical[i]);
StringGrid2->Cells[i][0]=IntToStr(total_Horizontal[i]);
StringGrid3->Cells[i][0]=IntToStr(difference_Horizontal[i]);
}
StringGrid9->Cells[0][0]=IntToStr(A);
StringGrid7->Cells[0][0]=IntToStr(B);
StringGrid6->Cells[0][0]=IntToStr(C);
StringGrid8->Cells[0][0]=IntToStr(D);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Close();
}
Brak komentarzy:
Prześlij komentarz