Autor Beitrag
cerebrum
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Sa 15.02.03 12:55 
Hi!
Wie kann ich prüfen, ob die Wurzel aus einer Zahl ganzzahlig oder rational ist?
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 15.02.03 13:57 
probier doch mal:
ausblenden Quelltext
1:
2:
a:=sqrt(b);
if Trunc(a) = a then ShowMessage('Ganzzahlig!');


MfG,
Peter

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
DaRkFiRe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 526

WinXP Home & Professional
C, C++, Delphi
BeitragVerfasst: Sa 15.02.03 16:08 
Man kann auch ...

ausblenden Quelltext
1:
2:
a:=sqrt(b); 
if INT(a) = a then ShowMessage('Ganzzahlig!');


... schreiben :)

_________________
Lang ist der Weg durch Lehren - kurz und wirksam durch Beispiele! Seneca
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: Sa 15.02.03 18:28 
... und spart sich somit ein paar Umwandlungen, die Rechenzeit in Anspruch nehmen. :idea:

_________________
Ist Zeit wirklich Geld?
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 15.02.03 18:31 
Beide Funktionen beanspruchen Rechenzeit. Und welche davon schneller ist, ist noch gar nicht gesagt. Allerdings beinhaltet Int eine Rundungsfunktion, so dass hier evtl. sogar mehr Rechenzeit in Anspruch genommen wird. Aber mal ehrlich: meinst Du wirklich, dass der Unterschied bei heutigen Rechnern irgendwie von Bedeutung ist? Wohl kaum, oder?

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".