Last active
October 20, 2017 01:03
-
-
Save diogocapela/fa080ad4b7326b84141671979df1464a to your computer and use it in GitHub Desktop.
APROG - PL04 Algoritmia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: num, alg, somaPares | |
INÍCIO | |
somaPares = 0 | |
REPETE | |
LER(num) | |
ENQUANTO(num <= 0) | |
REPETE | |
alg = num MOD 10 | |
SE(alg MOD 2 == 0) | |
somaPares = somaPares + alg | |
FIMSE | |
num = num DIV 10 | |
ENQUANTO(num > 0) | |
ESCREVER('A soma dos algarismos pares é: ' + somaPares) | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: num, alg, somaPares | |
INÍCIO | |
somaPares = 0 | |
LER(num) | |
ENQUANTO(num > 0) | |
REPETE | |
alg = num MOD 10 | |
SE(alg MOD 2 == 0) | |
somaPares = somaPares + alg | |
FIMSE | |
num = num DIV 10 | |
ENQUANTO(num > 0) | |
ESCREVER('A soma dos algarismos pares é: ' + somaPares) | |
LER(num) | |
FIMENQUANTO | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: num, alg, produtoImpares | |
INÍCIO | |
produtoImpares = 1 | |
REPETE | |
LER(num) | |
ENQUANTO(num <= 0) | |
REPETE | |
alg = num MOD 10 | |
SE(alg MOD 2 != 0) | |
produtoImpares = produtoImpares * alg | |
FIMSE | |
num = num DIV 10 | |
ENQUANTO(num != 0) | |
ESCREVER('O produto dos algarismos impares é: ' + produtoImpares) | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: num, alg, produtoImpares, n | |
INÍCIO | |
REPETE | |
LER(n) | |
ENQUANTO(n <= 0) | |
PARA(i = 1 ATE n PASSO 1) | |
produtoImpares = 1 | |
REPETE | |
LER(num) | |
ENQUANTO(num <= 0) | |
REPETE | |
alg = num MOD 10 | |
SE(alg MOD 2 != 0) | |
produtoImpares = produtoImpares * alg | |
FIMSE | |
num = num DIV 10 | |
ENQUANTO(num != 0) | |
ESCREVER('O produto dos algarismos impares é: ' + produtoImpares) | |
FIMPARA | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
R: O algoritmo calcula o dobro do produto dos algarismos impares de um determinado número. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: num, num1, dig | |
INÍCIO | |
LER(num) | |
SE(num MOD 2 == 0 && num MOD 3 != 0) | |
num1 = 0 | |
ENQUANTO(num != 0) | |
dig = num MOD 10 | |
num1 = num1 * 10 + dig | |
num = num DIV 10 | |
FIMENQUANTO | |
ESCREVER('Resultado: ' + 2*num1) | |
SENÃO | |
ESCREVER('Input não aceite. O número não é par e não múltiplo de 3.') | |
FIMSE | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
R: O algoritmo inverte um determinado número e multiplica-o por 2. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: num, num1, dig, ord | |
INÍCIO | |
LER(num) | |
SE(num >= 100 && num <= 10000) | |
num1 = 0 | |
ord = 0 | |
ENQUANTO(num != 0) | |
dig = num MOD 10 | |
SE (dig MOD 2 == 0) | |
num1 = num1 + dig * potencia(10, ord) | |
ord = ord + 1 | |
FIMSE | |
num = num DIV 10 | |
FIMENQUANTO | |
ESCREVER('Resultado: ' + num1) | |
SENÃO | |
ESCREVER('O número introduzido tem menos de 3 ou mais de 5 algarismos.') | |
FIMSE | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: num8, num10, alg, ordem | |
INÍCIO | |
num10 = 0 | |
ordem = 0 | |
REPETE | |
LER(num8) | |
ENQUANTO(num8 <= 0) | |
ENQUANTO(num8 > 0) | |
alg = num8 MOD 10 | |
num10 = num10 + alg * 8^ordem | |
ordem = ordem + 1 | |
num8 = num8 DIV 10 | |
FIMENQUANTO | |
ESCREVER('O número em base 10 é: ' + num10) | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Input | |
let num8 = 432423; | |
// Processo | |
let num10 = 0; | |
let ordem = 0; | |
while(num8 > 0) { | |
let alg = num8 % 10; | |
num10 = num10 + alg * Math.pow(8, ordem); | |
ordem++; | |
num8 = Math.floor(num8 / 10); | |
} | |
console.log('O número em base 10 é: ' + num10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: num, base, num10, alg, ordem | |
INÍCIO | |
num10 = 0 | |
ordem = 0 | |
REPETE | |
LER(num) | |
LER(base) | |
ENQUANTO(num <= 0 || base <= 0 || base >= 10) | |
ENQUANTO(num > 0) | |
alg = num MOD 10 | |
num10 = num10 + alg * base^ordem | |
ordem = ordem + 1 | |
num = num DIV 10 | |
FIMENQUANTO | |
ESCREVER('O número em base 10 é: ' + num10) | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Input | |
let num = 24443423; | |
let base = 5; | |
// Processo | |
num10 = 0; | |
ordem = 0; | |
if(num <= 0 || base <= 0 || base >= 10) { | |
console.log('Valores introduzidos incorrectos.'); | |
} else { | |
while(num > 0) { | |
alg = num % 10; | |
num10 = num10 + alg * Math.pow(base, ordem); | |
ordem++; | |
num = Math.floor(num / 10); | |
} | |
console.log('O número em base 10 é: ' + num10); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: num10, octal, alg, ordem | |
INÍCIO | |
octal = 0 | |
ordem = 0 | |
REPETE | |
LER(num10) | |
ENQUANTO(num10 <= 0) | |
ENQUANTO(num10 > 0) | |
alg = num10 MOD 8 | |
octal = octal + alg * 10^ordem | |
ordem = ordem + 1 | |
num10 = num10 DIV 8 | |
FIMENQUANTO | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Input | |
let num10 = 312321; | |
// Processo | |
let octal = 0 | |
let ordem = 0 | |
while(num10 > 0) { | |
let alg = num10 % 8; | |
octal = octal + (alg * Math.pow(10, ordem)); | |
ordem++; | |
num10 = Math.floor(num10 / 8); | |
} | |
console.log(octal); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: num, clone, capicua, alg | |
INÍCIO | |
capicua = 0 | |
REPETE | |
LER(num) | |
ENQUANTO(num < 10) | |
clone = num | |
ENQUANTO(num > 0) | |
alg = num MOD 10 | |
capicua = capicua*10 + alg | |
num = num DIV 10 | |
FIMENQUANTO | |
SE(clone == capicua) | |
ESCREVER('O número é capicua.') | |
SENÃO | |
ESCREVER('O número não é capicua.) | |
FIMSE | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: num, maiorNum, menorImpar, alg, clone | |
INÍCIO | |
maiorNum = 0 | |
menorImpar = 10 | |
LER(num) | |
ENQUANTO(num != 0) | |
SE(num > maiorNum) | |
maiorNum = num | |
FIMSE | |
FIMENQUANTO | |
clone = maiorNum | |
REPETE | |
alg = clone MOD 10 | |
SE(alg MOD 2 != 0 && alg < menorImpar) | |
menorImpar = alg | |
FIMSE | |
clone = clone DIV 10 | |
ENQUANTO(clone > 0) | |
ESCREVER('O maior número introduzido foi: ' + maiorNum) | |
ESCREVER('O menor algarismo impar do maior número é: ' + menorImpar) | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: num, qnt | |
INÍCIO | |
qnt = 0 | |
REPETE | |
LER(num) | |
ENQUANTO(num <= 0) | |
PARA(i = 1 ATE num PASSO 1) | |
SE(num MOD i == 0) | |
qnt = qnt +1 | |
ESCREVER(i) | |
FIMSE | |
FIMPARA | |
ESCREVER('Total de divisores: ' + qnt) | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: num INTEIRO, primo BOOLEANO | |
INÍCIO | |
primo = true | |
REPETE | |
LER(num) | |
ENQUANTO(num <= 0) | |
PARA(i = 2 ATE num - 1 PASSO 1) | |
SE(num MOD i == 0) | |
primo = false | |
FIMSE | |
FIMPARA | |
SE(primo == true) | |
ESCREVER('O número ' + num + ' é um número primo.') | |
SENÃO | |
ESCREVER('O número ' + num + ' não é um número primo.') | |
FIMSE | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: num1, num2, minimoMultiploComum, cont | |
INÍCIO | |
minimoMultiploComum = 0 | |
cont = 1 | |
REPETE | |
LER(num1) | |
LER(num2) | |
ENQUANTO(num1 <= 0 || num2 <= 0) | |
ENQUANTO(minimoMultiploComum = 0) | |
SE(num1 MOD cont == 0 && num2 MOD cont == 0) | |
minimoMultiploComum = cont | |
FIMSE | |
cont = cont +1 | |
FIMENQUANTO | |
ESCREVER('O mínimo multiplo comum entre os 2 número é: ' + minimoMultiploComum) | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let num1 = 8; | |
let num2 = 12; | |
let count = 0; | |
let divisor; | |
if(num2 > num1) { | |
let clone = num1; | |
num1 = num2; | |
num2 = clone; | |
} | |
console.log('num1', num1) | |
console.log('num2', num2) | |
do { | |
divisor = num2 - count; | |
count = count + 1; | |
} while (num1 % divisor != 0 || num2 % divisor != 0) | |
console.log('minimo divisor comum:' + divisor); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: num INTEIRO, soma INTEIRO, cont INTEIRO, max INTEIRO, clone INTEIRO, alg, INTEIRO, soma INTEIRO, encontrou BOOLEANO | |
INÍCIO | |
cont = 0 | |
max = 15 | |
encontrou = false | |
ENQUANTO(cont < max && encontrou == false) | |
REPETE | |
LER(num) | |
ENQUANTO(num <= 0) | |
soma = 0 | |
clone = num | |
ENQUANTO(clone > 0) | |
alg = clone MOD 10 | |
soma = soma + alg | |
clone = clone DIV 10 | |
FIMENQUANTO | |
SE(soma MOD 2 == 0) | |
encontrou = false | |
FIMSE | |
FIMENQUANTO | |
SE(encontrou == true) | |
ESCREVER('A soma de todos os algarismos do número ' + num + ' é par.') | |
FIMSE | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: sequencia, num, total, div, percentagem, maiorPercentagem | |
INÍCIO | |
maiorPercentagem = 0 | |
REPETE | |
LER(sequencia) | |
ENQUANTO(sequencia <= 0) | |
PARA(i = 1 ATE sequencia PASSO 1) | |
total = 0 | |
div = 0 | |
REPETE | |
LER(num) | |
ENQUANTO(num <= 0) | |
clone = num | |
ENQUANTO(clone > 0) | |
alg = clone MOD 10 | |
SE(num MOD alg == 0) | |
div = div + 1 | |
FIMSE | |
clone = clone DIV 10 | |
total = total + 1 | |
FIMENQUANTO | |
percentagem = (div / total) * 100 | |
SE(percentagem > maiorPercentagem) | |
maiorPercentagem = percentagem | |
FIMSE | |
ESCREVER('A percentagem de algarismos que são divisores do próprio número é: ' + percentagem) | |
FIMPARA | |
ESCREVER('A maior das percentagens foi: ' + maiorPercentagem) | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: n INTEIRO, primo BOOLEANO | |
INÍCIO | |
REPETE | |
LER(n) | |
ENQUANTO(n <= 0) | |
PARA(i = 1 ATE n PASSO 1) | |
primo = true | |
PARA(k = 2 ATE i - 1 PASSO 1) | |
SE(i MOD k == 0) | |
primo = false | |
FIMSE | |
FIMPARA | |
SE(primo == true) | |
ESCREVER('O número ' + i + ' é um número primo.') | |
FIMSE | |
FIMPARA | |
FIM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ED: octal1, octal2, valido1, valido2 | |
INÍCIO | |
REPETE | |
valido1 = verdadeiro | |
valido2 = verdadeiro | |
LER(octal1) | |
LER(octal2) | |
clone1 = octal1 | |
clone2 = octal2 | |
ENQUANTO(clone1 > 0) | |
alg = clone1 MOD 10 | |
SE(alg > 7) | |
valido1 = false | |
FIMSE | |
clone1 = clone1 DIV 10 | |
FIMENQUANTO | |
ENQUANTO(clone2 > 0) | |
alg = clone2 MOD 10 | |
SE(alg > 7) | |
valido2 = false | |
FIMSE | |
clone2 = clone2 DIV 10 | |
FIMENQUANTO | |
ENQUANTO(valido1 == false OU valido2 == false) | |
FIM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment