int tab1[20][20];
int tab2[20][20];
bool __fastcall is_First(int value);
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
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::Button1Click(TObject *Sender)
{
int i,j,k,sum1,sum2;
float average1,average2;
int temp_tab1[20*20];
int temp_tab2[20*20];
k=sum1=sum2=0;
i=1;
do
{
if(i%2!=0)
{
temp_tab1[k]=i;
sum1+=i;
++k;
}
++i;
}while(k<20*20);
k=0;
i=1;
do
{
if(i%2==0)
{
temp_tab2[k]=i;
sum2+=i;
++k;
}
++i;
}while(k<20*20);
k=0;
for(i=0;i<20;i++)
{
for(j=0;j<20;j++)
{
tab1[i][j]=temp_tab1[k];
tab2[i][j]=temp_tab2[k];
++k;
}
}
int temp_sum;
int sum_first;
float average_first1;
float average_first2;
sum_first=0;
for(i=0;i<20;i++)
{
for(j=0;j<20;j++)
{
StringGrid1->Cells[i][j]=IntToStr(tab1[j][i]);
StringGrid2->Cells[i][j]=IntToStr(tab2[j][i]);
temp_sum=tab1[i][j]+tab2[i][j];
if(is_First(temp_sum))
{
ListBox1->Items->Add(IntToStr(tab1[i][j])+" + "+IntToStr(tab2[i][j])+" = "+IntToStr(temp_sum));
sum_first+=temp_sum;
}
}
}
average1=(1.*sum1)/(20.*20.);
average2=(1.*sum2)/(20.*20.);
average_first1=(100.*sum_first)/(1.*sum1);
average_first2=(100.*sum_first)/(1.*sum2);
Edit1->Text=IntToStr(sum1);
Edit2->Text=IntToStr(sum2);
Edit3->Text=FloatToStr(average1);
Edit4->Text=FloatToStr(average2);
Edit5->Text=FloatToStr(average_first1)+"%";
Edit6->Text=FloatToStr(average_first2)+"%";
}
Brak komentarzy:
Prześlij komentarz