11.07.2015 Views

Lista 03a - DCC/UFMG

Lista 03a - DCC/UFMG

Lista 03a - DCC/UFMG

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

47) Sendo H = 1 - 21 + 31 - 41 + ... N1 , faça um algoritmo em PORTUGOL para gerar onúmero H. O número N é lido do teclado.algoritmo L3P047;varinteiro: N, C;real: H;inícioH ← 0;leia(N);para C de 1 até N façase ( C mod 2 = 1 ) entãoH ← H + 1 / C; { termo ímpar }senãoH ← H - 1 / C; { termo par }fim-sefim-paraimprima("H = ",H);fimprogram l3p047;varN, C: integer;H: real;beginwrite('Digite um numero: ');readLn(N);H := 0;for C := 1 to N dobeginif ( C mod 2 = 1 ) thenH := H + 1 / C { termo impar }elseH := H - 1 / C; { termo par }end;writeLn('H = ',H:5:4);end.% N, C: integer;% H: real;N = input('Digite um numero: ');H = 0;for C = 1 : Nif ( mod(C,2) == 1 )H = H + 1 / C; % termo imparelseH = H - 1 / C; % termo parendendfprintf(1,'H = %f\n',H);<strong>UFMG</strong> – ICEx – <strong>DCC</strong> – Programação de Computadores – 2º. Sem 2005 – David Menoti 48

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

Saved successfully!

Ooh no, something went wrong!