Einzelnen Beitrag anzeigen
Ungelesen 31.01.11, 12:20   #3
wmosebach
Ist öfter hier
 
Registriert seit: Jan 2010
Beiträge: 189
Bedankt: 117
wmosebach ist noch neu hier! | 0 Respekt Punkte
Standard

Ansich stimmt es schon fast, brauchst nur 1 2 Änderungen zu unternehmen:

Code:
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#include <math.h>

using namespace std;

int main(int argc, char *argv[])
{
srand(time(0));

double x,y,z,pi;
int n = 0;
for (int i=1; i<=1000; i++){
x=(double)rand()/(double)RAND_MAX;
y=(double)rand()/(double)RAND_MAX;
z=x*x+y*y;
if (z<1){
n++;
}
}
pi=4*n/1000;
cout << pi << endl;

system("PAUSE");
return EXIT_SUCCESS;
}
Allgemein:
pow is ne ganz böse funktion, nutze lieber x*x wenn es solch einfache Berechnungen sind

ob rand() so funktioniert, wei ich nicht 100%ig, aber so sollte die Funktion umgesetzt werden können
__________________
Make the world a prettier place - get a bikini wax!
wmosebach ist offline   Mit Zitat antworten