evo ti kod. napisao sam u delphi, al ako ne umes da prebacis onda bem li ga :)
Code:
program Mnozenje;
{$APPTYPE CONSOLE}
uses
SysUtils;
var A, B, C, D: string;
Action: char;
function Vrednost(c: char): byte;
begin
Result := Ord(c) - 48;
end;
procedure Saberi(A, B: string; var C: string);
var p, i: byte;
begin
//da se izjednace duzine A, B i C
while Length(A) > Length(B) do
B := '0' + B;
while Length(A) < Length(B) do
A := '0' + A;
SetLength(C, Length(A));
//sabiranje cifra po cifra
p := 0;
for i := Length(A) downto 1 do
begin
C[i] := Chr((p + Vrednost(A[i]) + Vrednost(B[i])) mod 10 + 48);
p := (p + Vrednost(A[i]) + Vrednost(B[i])) div 10;
end;
//ako ima prenos dodati na pocetak
if p > 0 then
C := Chr(p + 48) + C;
end;
procedure Mnozi(A, B: string; var C: string);
var i, j, p: byte;
temp: char;
begin
//da se izjednace duzine A, B i C i postaviti C na 0;
while Length(A) > Length(B) do
B := '0' + B;
while Length(A) < Length(B) do
A := '0' + A;
SetLength(C, 2 * Length(A));
for i := 1 to Length(C) do
C[i] := '0';
//mnozenje cifra po cifra
p := 0;
for i := Length(A) downto 1 do
begin
for j := Length(A) downto 1 do
begin
temp := Chr((p + Vrednost(C[i + j]) + Vrednost(A[i]) * Vrednost(B[j])) mod 10 + 48);
p := (p + Vrednost(C[i + j]) + Vrednost(A[i]) * Vrednost(B[j])) div 10;
C[i + j] := temp;
end;
//ako ima prenosa dodati na pocetak tekuceg sabirka
if p > 0 then
begin
C[i] := Chr(p + 48);
p := 0;
end;
end;
//obrisati prve nule
while C[1] = '0' do
Delete(C, 1, 1);
end;
begin
while True do
begin
Write('A = '); ReadLn(A);
Write('B = '); ReadLn(B);
WriteLn;
Saberi(A, B, C);
WriteLn('A + B = ', C);
Mnozi(A, B, D);
WriteLn('A * B = ', D);
WriteLn(#13, 'Nastaviti? (D/N)');
ReadLn(Action);
if UpCase(Action) = 'N' then
Break;
end;
end.
pozdravi
Ride the rainbow, crack the sky
DIY gitare, pojacala i efekti
www.diy-fever.com