Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h> //GENERAR NUMEROS
- #include <time.h> //TOMA EL TIEMPO
- #include <math.h> //GALERIA MATEMATICA
- using namespace std;
- unsigned t0, t1;
- //////////////////////////////////////////////////////////////////////////////////
- double calcularPi(double cuadros){
- double sumatoria = 0, auxiliar;
- for (int i = 1; i <= cuadros; i++){
- auxiliar = (-4)*pow(-1,i)/(2*i-1);
- sumatoria = sumatoria + auxiliar;
- }
- return sumatoria;}
- //////////////////////////////////////////////////////////////////////////////////
- int main(void){
- double cuadros;
- cout<<"\n\t - INGRESA LA CANTIDAD DE CUADROS:\t";
- cin>>cuadros;
- t0=clock();
- cout<<"\n\t - VALOR DE PI CON "<<cuadros<<" CUADROS:\t"<<calcularPi(cuadros);
- t1 = clock();
- double tiempo = (double(t1-t0)/CLOCKS_PER_SEC);
- cout<<"\n\t - TIEMPO DE EJECUCION:\t"<< tiempo << endl;
- return 0;}
Advertisement
Add Comment
Please, Sign In to add comment