C++ pi ədədinin hesablanması üçün kömək lazımdır
salam, oktyabrın 18də saat 4əcən pi ədədinin c++ hesablanması üçün kod lazımdır mənə. İndiyə qədər neçə metodu yoxlamışam alınmır. Monte Carlo üsulu ilə hesablamaq lazımdır və java bilən birindən aldım buna oxşasın
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package areacalc;
import java.util.*;
import java.io.*;
public class Areacalc {
private double x1,y1, x2, y2 , x3,y3 ;
private int counter;
private int n=10000000;
private double aq;
public double randomnumb(){
x1= Math.random() * ( 1 - 0 );
//x2= (int) Math.random () * (1-0);
y1= Math.random() * ( 1 - 0 );
//y2= (int) Math.random () * (1-0);
x3= (double) Math.sqrt( x1*x1 + y1*y1);
//y3=(int)Math.sqrt(x1^2 + y1^2);
return x3;
}
public double result (){
for (int i=0 ; i < n ; i++ ){
if (randomnumb() <= 1){ counter++ ;}
}
aq= (double )counter/n;
return aq;
}
public static void main(String[] args) {
Areacalc aaa= new Areacalc ();
//aaa.randomnumb();
//System.out.println(aaa.result());
//System.out.println(aaa.result());
System.out.println("Pi is:" + aaa.result()*4);
}
}