piątek, 6 września 2019

Continuation of the previous example (Visual C++)



#pragma endregion
System::Boolean is_First(int value)
{
int i,sum=0;
for(i=1;i<value+1;i++)
if(value%i==0)
++sum;
if(sum==2)
return true;
else
return false;


}
int *tab1, *tab2,  *tab3;

private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
Close();
}
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
int h_many1,h_many2,h_many3,i,j;
h_many1=h_many2=h_many3=0;
for(i=0;i<1001;i++)
if(is_First(i))
++h_many1;
for(i=1000;i<2001;i++)
if(is_First(i))
++h_many2;
for(i=2000;i<3001;i++)
if(is_First(i))
++h_many3;
label7->Text=h_many1.ToString();
label8->Text=h_many2.ToString();
label9->Text=h_many3.ToString();
tab1=new int[h_many1];
tab2=new int[h_many2];
tab3=new int[h_many3];
i=0;
j=1;
do
{
if(is_First(j))
{
tab1[i]=j;
++i;
}
++j;
}while(i<h_many1);
i=0;
j=1000;
do
{
if(is_First(j))
{
tab2[i]=j;
++i;
}
++j;
}while(i<h_many2);
i=0;
j=2000;
do
{
if(is_First(j))
{
tab3[i]=j;
++i;
}
++j;
}while(i<h_many3);
Graphics^ a1=panel1->CreateGraphics();
Graphics^ a2=panel2->CreateGraphics();
Graphics^ a3=panel3->CreateGraphics();
Pen^ p1=gcnew Pen(System::Drawing::Color::Yellow);
Pen^ p2=gcnew Pen(System::Drawing::Color::Red);
Pen^ p3=gcnew Pen(System::Drawing::Color::Green);

p1->Width=2;
p2->Width=2;
p3->Width=2;
int height=panel1->Height;
             int h1,h2,h3;
h1=h2=h3=height;
for(i=1;i<h_many1;i++)
{
a1->DrawLine(p1,tab1[i-1],h1,tab1[i],h1);
h1-=1;

}
for(i=1;i<h_many2;i++)
{
a2->DrawLine(p2,-1000+tab2[i-1],h2,-1000+tab2[i],h2);
h2-=1;
for(i=1;i<h_many3;i++)
{
a3->DrawLine(p3,tab3[i-1]-2000,h3,tab3[i]-2000,h3);
h3-=1;
}

delete tab1;
delete tab2;
delete tab3;

}

Brak komentarzy:

Prześlij komentarz