Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Skracivanje razlomka, gdje grijesim....??

[es] :: Pascal / Delphi / Kylix :: Skracivanje razlomka, gdje grijesim....??

[ Pregleda: 2691 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Kupushich
Martina Prgomet

Član broj: 97582
Poruke: 5
*.adsl.net.t-com.hr.



Profil

icon Skracivanje razlomka, gdje grijesim....??19.06.2006. u 10:36 - pre 217 meseci
U delphiju imam zadatak skratiti razlomak (graficko sucelje), i ja znam kako to otprilike ide ali ne znam sve... pa ako moze pomoc...
evo ovo sto sam ja napravila dosad(ima gresaka ali ne znam ispraviti...)

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit; //za unos brojnika
Edit2: TEdit; //za unos nazivnika
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel; //treba ispisati skraceni brojnik
Label5: TLabel;
Label6: TLabel; //treba ispisati skraceni nazivnik
Button1: TButton;
Button2: TButton;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
{$R *.dfm}

procedure TForm1.Button2Click(Sender: TObject);
begin
Halt;
end;

procedure TForm1.Button1Click(Sender: TObject);
var x,y,a,b,i:integer;
begin
a:=strtoint(edit1.text);
b:=strtoint(edit2.Text);
if a<b then
begin
x:=a; y:=b;
end
else
begin
y:=a; x:=b;
end;
for i:= 1 to x do
if (x mod i=0) and (y mod i=0) then d:=n;
label4.Caption:= floattostr(strtofloat(a/d));
label6.Caption:= floattostr(strtofloat(b/d));
end;

end.

Kupushich
 
Odgovor na temu

Kupushich
Martina Prgomet

Član broj: 97582
Poruke: 5
*.adsl.net.t-com.hr.



Profil

icon Re: Skracivanje razlomka, gdje grijesim....??19.06.2006. u 11:18 - pre 217 meseci
Sad sam ga riješila na drugi način, ali ni to ne radi, MOLIM VAS, POMOĆ!!!!
Evo...

var b,n,i,j:integer;
begin
a:=strtoint(edit1.text);
b:=strtoint(edit2.text);
for i:=2 to a do
if (a mod i =0) and (b mod i =0) then begin
repeat
a:=b div i; b:=n div i;
until (a mod i<>0) or (b mod i<>0);end;
label4.caption:=inttostr(a);
label6.caption:=inttostr(b);
end.
Kupushich
 
Odgovor na temu

Whois

Član broj: 92214
Poruke: 37
*.panet.co.yu.



Profil

icon Re: Skracivanje razlomka, gdje grijesim....??19.06.2006. u 12:15 - pre 217 meseci
Code:

for i:= a downto 2 do
  if (a mod i=0) and (b mod i=0) then
    begin
      a:=a div i;
      b:=b div i;
    end;
 
Odgovor na temu

[es] :: Pascal / Delphi / Kylix :: Skracivanje razlomka, gdje grijesim....??

[ Pregleda: 2691 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.