Mam program który oblicza całke metoda Monte Carlo.
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <fstream>
#include <math.h>
using namespace std;
double f(double x)
{
return sqrt(1-pow(x,2));
}
int main()
{
int const N =100000;
double b, e, s, dx;
int i, p ;
cout<<"Podaj poczatek przedzialu"<<endl;
cin >> b ;
cout<<"Koniec przedzialu"<<endl;
cin >> e;
srand((unsigned)time(NULL));
s = 0;
dx = b - e;
for(i = 1; i <= N; i++)
s += f(e+((double)rand()/(double)(RAND_MAX+1)*dx));
s = dx * s / N;
cout<< "Wartosc calki wynosi"<< s<< endl;
system ("PAUSE");
return 0;
}
Jak zapętlic to żeby obliczył np 10000 razy? Wiem ze petla ale gdzie ta petle wstawic i co pozmieniac z paramatrem s?
Dziekuje za pomoc.