![]() |
Beliebig lange Dezimalstellen ab einer beliebigen Stelle...
Hier ist mal ein kleiner Codesnippet, welchen ich verfasst habe, um diverse Programmieraufgaben (beispielsweise
![]()
Code:
(Aufgabe, falls die Seite irgendwann einmal down gehen sollte)
Infinite division Calculate 13155187 / 13417 with 5000 decimals. The solution is the last 6 numbers (of those 5000 decimals).
Delphi-Quellcode:
MfG,
type
TByteArray = Array of Byte; function GetDecimalValues(Dividend: Integer; const Divisor: Integer; From: DWord; const Digits: DWord): TByteArray; var BeforeComma: Boolean; Remainder: Integer; Pos, i: Integer; begin if From = 0 then From := 1; if Digits = 0 then Exit; SetLength( Result, Digits ); BeforeComma := True; repeat Remainder := Dividend mod Divisor; if (Remainder < Divisor) and (BeforeComma) then begin BeforeComma := False; Pos := 0; end; i := Pos - From + 1; if (i < Digits) and (i >= 0) then Result[i] := ( Remainder * 10 ) div Divisor; Dividend := Remainder * 10; if not BeforeComma then inc( Pos ); until Pos >= From + Digits - 1; end; // Möglicher Aufruf: var D: TByteArray; begin { 113 / 35 = 3,228571428571428571428... } D := GetDecimalValues( 113, 35, 1, 4 ); // D = [2,2,8,5] end; Aphton |
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:59 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz