Ȼ
6
: .
: Builder C++ StringGrid, Memo.
: :
-241 .. ..
-.2015
: - .
:6. a1,a2,a3,,an.. .
:
:
1. :
, , . ,
:
< > [n1 ];
n1- . ( ). .
2. Builder C++:
1:
, :
for (i=0; i<n; i++)
{
printf ("A[%d]=",i); scanf ("%d",&A[i]);
}
2:
:
int random (int n);
{
return rand()%n;
}
#include <stdio.h>
------------------------------
randomizer ();
for (i=0;i<n;i++)
{
A[i]=random(100);
}
3:
:
int A[5]={-1,-2,2,0}
3. Builder C++:
n :
for (i=0; i<n; i++)
cout >> a[i] >> " ";
(n ´ m) :
for (i=0; i<n; i++) //
{
for (j=0; j<m; j++) // m 2
printf("%5.1f ",a[i][j]); // 5
cout << ' \n '; // .
.
:
s=0;
for(i=0; i<n, i++)
{
s=s+A[i];
}
:
p=1;
for (i=0; i<n; i++)
{
p=p*A[i];
}
.
max=A[0];
nmax=0;
for (i=0; i<n; i++)
{
if (A[i]>max)
{
max=A[i];
nmax=i;
}
}
.
min=A[0];
for (i=0; i<n; i++)
{
if (min>A[i])
min=A[i];
}
:
|
|
:
#include <vcl.h> |
#pragma hdrstop |
#include "Unit1.h" |
#pragma package(smart_init) |
#pragma resource "*.dfm" |
TForm1 *Form1; |
int n; |
__fastcall TForm1::TForm1(TComponent* Owner) |
: TForm(Owner) |
{ |
} |
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key) |
{ |
if (Key== VK_RETURN) |
StringGrid1->Visible=true; |
} |
void __fastcall TForm1::Edit1Change(TObject *Sender) |
{ |
StringGrid1->Visible=true; |
n=StrToInt(Edit1->Text); |
StringGrid1->ColCount=n; |
} |
void __fastcall TForm1::Button1Click(TObject *Sender) |
{ |
randomize(); |
int a[100],i; |
for (i=0;i<n; i++) |
{ |
a[i]=random(100)-50; |
StringGrid1->Cells[i][0]=IntToStr(a[i]); |
} |
} |
void __fastcall TForm1::Button2Click(TObject *Sender) |
{ |
int a[100],i; |
int sum=0; |
for (i=0;i<n; i++) |
{ |
a[i]=StrToInt(StringGrid1->Cells[i][0]); |
if(a[0]>0) |
Lebel2->Caption=":"+IntToStr(a[0])+"" |
else |
Lebel2->Caption=":"+IntToStr(a[0])+" " |
} |
} |