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