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.

45) Seja a seguinte série:1, 4, 4, 2, 5, 5, 3, 6, 6, 4, 7, 7, ...Escreva um algoritmo em PORTUGOL que seja capaz de gerar os N termos dessasérie. Esse número N deve ser lido do teclado.algoritmo L3P045;varinteiro: N, C;inícioleia(N);para C de 1 até N façase ( C mod 3 = 1 ) entãoimprima( ( C div 3 ) + 1 ); { 1º, 4º, 7º , ... }senão-se ( C mod 3 = 2 ) entãoimprima( ( C div 3 ) + 4 ); { 2º, 5º, 8º , ... }senãoimprima( ( C div 3 ) + 3 ); { 3º, 6º, 9º , ... }fim-sefim-parafimprogram l3p045;varN, C: integer;beginwrite('Digite o numero de termos: ');read(N);for C := 1 to N dobeginif ( C mod 3 = 1 ) thenwriteLn( ( C div 3 ) + 1 ) { 1o, 4o, 7o , ... }else if ( C mod 3 = 2 ) thenwriteLn( ( C div 3 ) + 4 ) { 2o, 5o, 8o , ... }elsewriteLn( ( C div 3 ) + 3 ); { 3o, 6o, 9o , ... }end;end.N = input('Digite o numero de termos: ');for C = 1 : Nif ( mod(C,3) == 1 )fprintf(1,'%d\n', floor( C / 3 ) + 1 ) % 1o, 4o, 7o , ...elseif ( mod(C,3) == 2 )fprintf(1,'%d\n', floor( C / 3 ) + 4 ); % 2o, 5o, 8o , ...elsefprintf(1,'%d\n', floor( C / 3 ) + 3 ); % 3o, 6o, 9o , ...endend<strong>UFMG</strong> – ICEx – <strong>DCC</strong> – Programação de Computadores – 2º. Sem 2005 – David Menoti 46

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

Saved successfully!

Ooh no, something went wrong!