Andreas703
Mitglied
*löl* wie geht das?^^
Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature currently requires accessing the site using the built-in Safari browser.
int myArray[30];
myArray[4] = 123;
cout << myArray[4];
...
#include <iostream.h>
#include <conio.h>
#include <math.h>
#include <windows.h>
#include <time.h>
#define MAX_PRIME_COUNT 1000
int main() {
int w, x, y, z, a, iSqrt, iAktPrime = 0;
int piPrimes[MAX_PRIME_COUNT];
long zeit1,zeit2,zeit;
memset( piPrimes, 0, MAX_PRIME_COUNT);
time( &zeit1);
for( w = 3; w < 10000000 && iAktPrime < MAX_PRIME_COUNT - 1; w += 2) {
y = 0;
iSqrt = sqrt(w)
for( x=2; x < iSqrt; x++) {
z = w % x;
if(z == 0) {
y++;
break;
}
}
if(y == 0) {
piPrimes[ iAktPrime++] = x;
}
}
time(&zeit2);
zeit= zeit2 - zeit1;
for( x = 0; x < MAX_PRIME_COUNT && piPrimes[x] != 0; x++) {
cout << piPrimes[x] << endl;
}
getch();
}
int *piPrimes = new int[MAX_PRIME_COUNT];
statt
int piPrimes[MAX_PRIME_COUNT];
for( x=3; x < iSqrt; x+=2)
for( x = 0; x <= iAktPrime && piPrimes[x] < iSqrt; x++)
z = w % piPrimes[x];
naja ... das ist dann aber nicht wirklich eine Programmoptimierung. Mit dem Eurestatos Algo, den ich weiter oben vorgestellt hatte, habe ich im uebrigen die Laufzeit um mehr als ein drittel reduziert.umbrasaxum hat gesagt.:moin
Was du auch noch machen könntest ist die Priorität deines Programms gegenüber anderen Programm zu erhöhen, um sicher zustellen das dein Programm so schnell wie möglich laufen kann.
mfg
umbrasaxum