Additional , StringGrid 1 StringGrid 2 . ColCount 2, RowCount 1, .. , FixedCols FixedRows 0. DefaultColWidth 40.
StringGrid . Options goEditing StringGrid 1 true.
- :
...
int n = 4;
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
randomize(); // random ()
Edit1->Text=IntToStr(n);
StringGrid1->ColCount=n;
for(int i=0; i<n;i++) //
StringGrid1->Cells[i][0] = IntToStr(random(21)-10);
Label3->Hide(); //
StringGrid2->Hide();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
n=StrToInt(Edit1->Text);
if(n>10){
ShowMessage(" 10!");
n=10;
Edit1->Text = "10";
}
StringGrid1->ColCount=n;
for(int i=0; i<n;i++)
StringGrid1->Cells[i][0]=IntToStr(random(21)-10);
Label3->Hide();
StringGrid2->Hide();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
int i, kol = 0, a[10]; //
// StringGrid1
for(i=0; i<n;i++)
a[i]=StrToInt(StringGrid1->Cells[i][0]);
//
for(i=0; i<n;i++)
if(a[i]>=0) a[kol++] = a[i];
StringGrid2->ColCount = kol;
StringGrid2->Show(); //
Label3->Show();
// StringGrid2
for(i=0; i<kol;i++) StringGrid2->Cells[i][0]=IntToStr(a[i]);
}
( , main ):
...
#include <stdio.h>
#include <conio.h>
void main()
{
int a[10],n, i, kol=0;
randomize(); // random ()
printf("Input N (<=10) ");
scanf("%d", &n);
puts("\n Massiv A");
for(i=0; i<n;i++) {
|
|
a[i] = random(21)-10; //
printf("%4d", a[i]);
}
//
for(i=0; i<n;i++)
if(a[i]>=0) a[kol++] = a[i];
puts("\n Rezult massiv A");
for(i=0; i<kol;i++) printf("%4d", a[i]);
puts("\n Press any key... ");
getch();
}
:
. . , random ().
() Label, StringGrid.
, n , :
1. , .
2. , .
3. , .
4. , .
5. , .
6. , .
7. , .
8. , .
9. , , .
10. , .
11. , .
12. , .
13. , .
14. , , .
15. , .
16. , .