mendoza_franco

TP01_EJERCICIO04

Apr 21st, 2023 (edited)
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>     //GENERAR NUMEROS
  3. #include <time.h>       //TOMA EL TIEMPO
  4. #include <math.h>       //GALERIA MATEMATICA
  5. using namespace std;
  6. unsigned t0, t1;
  7. //////////////////////////////////////////////////////////////////////////////////
  8.     double calcularPi(double  cuadros){
  9.         double sumatoria = 0, auxiliar;
  10.             for (int i = 1; i <= cuadros; i++){
  11.                 auxiliar = (-4)*pow(-1,i)/(2*i-1);
  12.                 sumatoria = sumatoria + auxiliar;
  13.             }
  14.     return sumatoria;}
  15. //////////////////////////////////////////////////////////////////////////////////
  16.     int main(void){
  17.             double  cuadros;
  18.             cout<<"\n\t - INGRESA LA CANTIDAD DE CUADROS:\t";
  19.                 cin>>cuadros;
  20.         t0=clock();
  21.             cout<<"\n\t - VALOR DE PI CON "<<cuadros<<" CUADROS:\t"<<calcularPi(cuadros);
  22.         t1 = clock();
  23.     double tiempo = (double(t1-t0)/CLOCKS_PER_SEC);
  24.         cout<<"\n\t - TIEMPO DE EJECUCION:\t"<< tiempo << endl;
  25.     return 0;}
Advertisement
Add Comment
Please, Sign In to add comment