Hi,
ich habe gerade das Sieb des Eratosthenes in AutoIt gebaut und habe das in C++ übersetzt. Nur es gibt ein paar Probleme.
- SQRT verlangt komischerweise einen double
- Der Array lässt sich nicht deklarieren
- Und wenn ich dem Array bei der größenangabe statt einer Variable eine Zahl gebe ist dieses Problem nicht mehr, aber dann lässt er sich nicht mehr ausgeben.
Ich würd ja meine Frage auch im http://www.c-plusplus.de Forum Posten aber da kann man sich nicht mehr anmelden :S.
Hier ist der C++ Code
Spoiler anzeigen
#include<iostream>
using namespace std;
int main() {
double Zahl = 999.0;
double ZahlSqrt = sqrt(Zahl);
Zahl = static_cast<int>(Zahl);
ZahlSqrt = static_cast<int>(ZahlSqrt);
int aMatch[Zahl];
int MatchIndex = 0;
bool Match = false;
for (int x=2;x<Zahl;x++) {
for (int Teiler=2;Teiler<ZahlSqrt;Teiler++) {
if (!(x%Teiler)) {
Match = true;
goto LoopE;
}
}
LoopE:
if (Match = false) {
aMatch[MatchIndex] = x;
MatchIndex++;
}
Match = false;
}
for (int x=0;x<MatchIndex;x++) {
cout<<aMatch[x]<<"\n";
}
system("pause >nul");
return 0;
}
Alles anzeigen
Und die funktionierene Variante in AutoIt
Spoiler anzeigen
#include <Array.au3>
#include <Timers.au3>
$hGui = GUICreate("")
$iTime = 0
$iTimer = _Timer_SetTimer($hGui,1000,"_Update")
$MaxZahl = 100000
$MaxZahlSqrt = Int(Sqrt($MaxZahl))
Dim $aMatch[$MaxZahl]
[/autoit] [autoit][/autoit] [autoit]Global $MatchIndex = 0
Global $Match = False
For $x = 2 To $MaxZahl
For $Teiler = 2 To $MaxZahlSqrt
If Not Mod($x, $Teiler) Then
$Match = True
ExitLoop
EndIf
Next
If Not $Match Then
$aMatch[$MatchIndex] = $x
$MatchIndex += 1
EndIf
$Match = False
Next
_Timer_KillTimer($hGui,$iTimer)
ReDim $aMatch[$MatchIndex]
_ArrayDisplay($aMatch)
Func _Update($hWnd, $Msg, $iIDTimer, $dwTime)
$iTime += 1
ConsoleWrite("Aktuelle Zahl: " & $x & "|" & "Berechnete Prims: " & $MatchIndex & "|" & "Zeit: " & $iTime & " sek.|" & Int(($x * 100) / $MaxZahl) & "%" & @CRLF)
EndFunc
Ich hoffe ihr könnt mir Helfen !