11.07.2015 Views

Lista 03a - DCC/UFMG

Lista 03a - DCC/UFMG

Lista 03a - DCC/UFMG

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

51) O valor aproximado do número π pode ser calculado usando-se a série1 1 1 1S = 1 − + − + L3 3 3 33 5 7 93sendo π = S × 32 . Faça um algoritmo em PORTUGOL que calcule e imprima ovalor de π usando os 51 primeiros termos da séria acima.algoritmo L3P051;varinteiro: I;real: S, PI;inícioS ← 0;para I de 1 até 51 façase ( I mod 2 = 0 ) entãoS ← S - 1 / ( ( 2 * I – 1 ) ** 3 ); { termo par }senãoS ← S + 1 / ( ( 2 * I – 1 ) ** 3 ); { termo ímpar }fim-sefim-paraPI ← (S * 32) ** (1 / 3); { raiz cúbica através da potenciação}PI ← raiz(S * 32,3); { raiz cúbica através da função raiz}imprima("PI = ",PI);fimprogram l3p051;varI: integer;S, PI: real;beginS := 0;for I := 1 to 51 doif ( I mod 2 = 0 ) thenS := S - 1 / Exp( 3 * Ln( 2 * I - 1 ) ) { termo par }elseS := S + 1 / Exp( 3 * Ln( 2 * I - 1 ) ); { termo ímpar }PI := Exp( 1/3 * Ln(S * 32) ); { raiz cúbica através da potenciação}writeLn('PI = ',PI);end.% I: integer;% S, PI: real;S = 0;for I = 1 : 51if ( mod(I,2) == 0 )S = S - 1 / ( 2 * I - 1 ) ^ 3; % termo parelseS = S + 1 / ( 2 * I - 1 ) ^ 3; % termo ímparendendPI = ( S * 32 ) ^ ( 1 / 3 ); % raiz cúbica através da potenciaçãofprintf(1,'PI = %f\n',PI);fprintf(1,'Pi = %f\n',pi);<strong>UFMG</strong> – ICEx – <strong>DCC</strong> – Programação de Computadores – 2º. Sem 2005 – David Menoti 53

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!