
Добавил:
masterdos
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
int n =5;
//---------------------------------------------------------------------------
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 a[10], b[10], k, sum=0, i;
for(i=0; i<n;i++)
a[i]=StrToInt(StringGrid1->Cells[i][0]);
for(k=0;k<n;k++) {
for(i=0;i<=k;i++)
sum+=a[i];
b[k]=sum;
sum=0;
}
for(k=0; k<n;k++)
b[k]=StrToInt(StringGrid2->Cells[k][0]);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Edit1->Clear();
}
//---------------------------------------------------------------------------
Соседние файлы в папке 6.2.1