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.

38) Escreva um algoritmo em PORTUGOL que determine se um dado número N (digitadopelo usuário) é primo ou não.algoritmo L3P038;varinteiro: N, C;lógico: SIT;inícioSIT ← verdadeiro;leia(N);C ← 2 ;enquanto ( SIT e C < N ) façase (N mod C = 0 ) entãoSIT ← falso;fim-seC ← C + 1;fim-enquantose ( SIT ) entãoimprima(N," é primo!");senãoimprima(N," não é primo!");fim-sefimprogram l3p038;varN, C: integer;SIT: boolean;beginwrite('Digite um numero: ');read(N);SIT := true;C := 2;while ( SIT ) and ( C < N ) dobeginif (N mod C = 0 ) thenSIT := false;C := C + 1;end;if ( SIT ) thenwriteLn(N,' eh primo!')elsewriteLn(N,' nao eh primo!');end.% N, C: integer;% SIT: boolean;N = input('Digite um numero: ');SIT = 1; % trueC = 2;while ( SIT ) & ( C < N )if (mod( N , C ) == 0 )SIT = 0; % falseendC = C + 1;endif ( SIT )fprintf(1,'%d eh primo!',N);elsefprintf(1,'%d nao eh primo!',N);end<strong>UFMG</strong> – ICEx – <strong>DCC</strong> – Programação de Computadores – 2º. Sem 2005 – David Menoti 38

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

Saved successfully!

Ooh no, something went wrong!