type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
const n=10;
procedure chiqarish;
var
i:integer;
begin
for i:=1 to n do
Memo1.Lines.add('5');
end;
begin
chiqarish; Memo1.Lines.add(' ekranda 10 ta besh');
chiqarish; Memo1.Lines.add(' ekranda 20 ta besh');
end;
end.
3-misol. n! ni hisoblash dasturini tuzing.
Dastur kodi va oynaning umumiy ko‘rinishini keltiramiz:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
n: integer; y: integer;
function fact(m: integer): integer;
var
k: integer;
begin
if m=0 then fact:=1 else fact:=fact(m-1) * m;
end;
begin
n:=strtoint(edit1.Text);
y:= fact(n);
Memo1.Lines.add('Natija='+inttostr(y));
end;
end.
Izoh: Hosil bo‘lgan dasturda foydalanib faktariyalni hisoblashingiz mumkin.
Buning uchun tepa qismiga qiymat kiritib, hisoblash tugmasini tanlash kifoya.
4-misol. Y x 5 funksiyani 2 x 10 oraliqda x 1; qadam bilan hisoblash dasturini tuzing.
Dastur kodi va oynaning umumiy ko‘rinishini keltiramiz:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i:real;
procedure qismdastur(x:real);
var
y:real;
begin
y:=x+4;
Memo1.Lines.add('Tub son='+floattostr(y));
end;
begin
i:=-2;
repeat
qismdastur(i); i:=i+1;
until i=10;
end; end.
5-misol. Quyidagi figurani yuzasini hisoblaymiz.
Dastur kodi va oynaning umumiy ko‘rinishini keltiramiz:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
arv
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
a,b,c,d,e,f,s:real;
s1,s2,s3,s4:real;
procedure Sq(x,y,z:real; var s:real);
var p:real;
begin
p:=(x+y+z)/2;
s:=sqrt(p*(p-x)*(p-y)*(p-z));
end;
begin
a:=strtofloat(edit1.Text);
b:=strtofloat(edit2.Text);
c:=strtofloat(edit3.Text);
d:=strtofloat(edit4.Text);
e:=strtofloat(edit5.Text);
f:=strtofloat(edit6.Text);
Sq(a,b,c,s1); Sq(c,d,e,s2); Sq(b,e,f,s3); Sq(a,f,d,s4);
s:=s1+s2+s3+s4;
edit7.Text:='s='+floattostr(s);
end; end.
6-misol. Aylananing chapdan o‘ngga harakatini ko‘rsatadigan dastur tuzing.
1. Standart komponentalar palitrasining Data Access bandidagi
tugmacha tanlanadi va forma ustiga hosil qilinadi. Natijada “Timer1” tugmachasi paydo bo‘ladi.
2. Hosil bo‘lgan tugmacha ustiga sichqoncha tugmachasini ketma-ket ikki marta bosamiz va dasturlash maydoniga quyidagi dasturni kiritamiz.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
Do'stlaringiz bilan baham: |