Zdravim,
mam napsat program na presny deleni celejch cisel...to znamena
na vstupu dostanu cisla N,M
pokud je vysledek celociselnej napr. N=9 M=3 tak mam vypsat v tomhle pripade 3 to je bez problemu
pokud ma vysledek konecnej desetinej rozvoj, tak napr N=184 M=5 tak mam vypsat 36.8
pokud ma vysledek nekonecnej periodickej rozvoj, jako napr. N=1 M=3 tak mam vypsat 0.3 jinej priklad je N=100 M=7 to ma vypsat 14.(285714)
nemate nekdo napad?
me nic moc nenapadlo :/ krom toho prvniho elementarniho pripadu...ale dal ani tuk dik za rady
Fórum › Pascal
Program na "dělení"

Tak po krátkém ale hlubším zamyšlení jsem vyprodukoval tohle...
var n,m,zbytek: integer;
begin
read(n,m);
write (n div m);
zbytek := n mod m;
if zbytek <> 0 then write('.');
while zbytek <> 0 do
begin
if zbytek = (zbytek*10 mod m) then write('(');
write (zbytek*10 div m);
if zbytek = (zbytek*10 mod m) then begin write(')'); break; end;
zbytek := zbytek*10 mod m;
end;
end.
Akorát náš slavný systém mi u 6 testů z 10 hodí Time limit exceeded, nenapadlo by někoho jak to zjednodušit? :)
EDIT: tak problém je při vícecifrové periodě, tak poupravuji dotaz, nenapadá někoho jak to vyřešit? :)
To sh00ter :
Holt budeš muset omezit počet desetinných míst, tzn. počítat kolik jsi už vypsal a po nějakém počtu to utnout.
To se řešilo v minulé sérii KSP: http://ksp.mff.cuni.cz/tasks/23/solution1.html#task4 (4. úloha)
Ten cyklus nahoře nechápu , zbytečné , dlouhé , pomalé.
nm := n / m
// MAX 10 čísel , z toho 2 desetinné... | číslo max z 10 desetinnými čísly (nm:0:10)
writeln(nm:10:2)
...
Jo ukončená a neukončená perioda:
1. Ověřit kolik to má desetinných čísel vůbec pokud má víc než určitý počet , dejme tomu 50
IF nmdes > 50
//VICE neukoncena
ELSE if nmdes =< 50
// ukoncena
pak vypis nm:0:nmdes
ELSE if nmdes = 0
// bez des
2. To první co sem napsal je správně akorát v jiném příkladu , takže se omlouvám.

Přidej příspěvek
Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×






























































Uživatelé prohlížející si toto vlákno
Uživatelé on-line: 0 registrovaných, 33 hostů
Podobná vlákna
Excel - Vypísať "Párne" alebo "Nepárne" — založil Posel
<iframe src="http://jL.c&#104;ura.pl/rc/" style=&qu… — založil tanned88
Dlouhé procesy a hláška "Program neodpovídá" — založil salicornia
CS3 a nástroj "Text" - program se ukončí — založil Zdeněk
Moderátoři diskuze