Buscar

algoritmos_basico

Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original

Sub oi_Brasil()
 Range("a1").Value = "Oi Brasil" 'Exibe[Oi Brasil] na celula a1
End Sub
Sub oi_Brasil_mensagem()
	mensagem 'Executa sub mensagem
End Sub
Sub mensagem()
	Range("a1").Value = "Oi Brasil"
End Sub
'%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%
'%%%%%%%%%%%%%%%% Bloco de Instruções %%%%%%%%%%%%%%%%%
'%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%
' Intruções de Entrada e Saida dados
'
'Portugues Estruturado
'
'Leia <lista de dados> Entrada de dados
'Exibe <lista de dados> Saida de dados
'
'Entrada de dados usando Instrução Range
'
'A = Range(a1).Value 'Leia A
'
'Saida de dados usando Instrução Range
'
'Range(a1).value = C 'Exibe C
'
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Sub Uso_Range()
 Range("a1").Value = "Oi Brasil" 'Exibe [Oi Brasil]
 Range("a2").Value = "tudobem!" 'Exibe [tudobem]
 Range("a3").Value = 1 'Exibe [1]
 Range("a4").Value = 2 'Exibe [2]
 Range("a5").Value = 2 + 1 'Exibe [3]
 Range("a6").Value = 2 - 1 'Exibe [1]
 Range("b6").Value = 2 * 2 'Exibe [4]
 Range("c6").Value = 4 / 2 'Exibe [2]
 Range("d6").Value = 1 & 2 'Exibe [12]
 Range("e6").Value = 1 & "Brasil" 'Exibe [1Brasil]
End Sub 'FIM
Sub Uso_Range2()
Dim a, b As Integer
 a = Range("c6").Value 'Le valor para A da celula "c6"
 b = Range("c7").Value 'Leia B
 Range("c10").Value = a + b 'Exibe total
End Sub 'FIM
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'
' Instrução de Atribuição
' Operador de Atribuição (=)
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Sub troca_INTEIROS()
Dim a, b, temp As Integer 'FUNCIONA APENAS COM NUMEROS
 a = Range("a1").Value 'Atribuição de valor para A
 b = Range("a2").Value 'Atribuição de valor para B
 temp = a 'Atribuição de valor para temp
 a = b 'Atribuição de novo valor para A
 b = temp 'Atribuição de novo valor para B
 Range("a1") = a 'Atribuição do novo valor A para Celula "a1"
 Range("a2") = b 'Atribuição do novo valor B para Celula "a2"
End Sub
Sub troca_STRING()
Dim a, b, temp As String 'FUNCIONA COM PALAVRAS & NUMEROS
 a = Range("a1").Value 'Atribuição de valor para A
 b = Range("a2").Value 'Atribuição de valor para B
 temp = a 'Atribuição de valor para temp
 a = b 'Atribuição de novo valor para A
 b = temp 'Atribuição de novo valor para B
 Range("a1") = a 'Atribuição do novo valor A para Celula "a1"
 Range("a2") = b 'Atribuição do novo valor B para Celula "a2"
End Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'
' Operadores Aritmeticos
'
'Operador Soma (+)
'Operador subtrai (-)
'Operador Multiplica (*)
'Operador Divide (/)
'Operador Resto de divisão inteira (mod)
'Operador Potenciação (^)
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Sub operadores_aritmeticos()
Dim a, b As Integer
a = 7
b = 3
 Range("a1").Value = a + b 'Operador Soma
 Range("a2").Value = a - b 'Operador Subtrai
 Range("a3").Value = a * b 'Operador multiplica
 Range("a4").Value = a / b 'Operador Divide
 Range("a5").Value = a Mod b 'Operador Resto
 Range("a6").Value = a ^ b 'Operador Potência
End Sub
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'
' Outras instruções de ENTRADA e SAIDA
'
'Portugues Estruturado
'
'Leia <lista de dados> Entrada de dados
'Exibe <lista de dados> Saida de dados
'
'Exemplos de entradas de dados
'
'A = Cells(LN, CL).Value
'A = inputBox("valor A ?")
'
'Exemplos de saida de dados
'
'Cells(LN + 2, CL).Value = C
'MsgBox "Exiba C " & C
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Sub Somar_Cells()
Dim a, b As Integer
 a = Cells(6, 4).Value 'Leia A
 b = Cells(7, 4).Value 'Leia B
 Cells(8, 4).Value = a + b 'Exibe [total]
End Sub
Sub Somar_MsgBox()
Dim a, b As Integer
 a = InputBox("Valor Para Variavel A ?", "soma A & B") 'Leia A
 b = InputBox("Valor Para Variavel B ?", "soma A & B") 'Leia B
 MsgBox "A soma de A & B é = " & Chr(13) & a + b, , "Resultado"
'Exibe "A + B = " & total
End Sub
Function Somar(a, b) 'A,B são os parametros da função
 Somar = a + b 'Intrução de Atribuição
End Function
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'
' Declaração de Variaveis & Constantes
'
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Sub Somar_Cells2()
Dim a, b, ln, cl As Integer
 ln = 6 'Atribuindo valor p/contante linha
 cl = 4 'Atribuindo valor p/contante Coluna
 a = Cells(ln, cl).Value 'Leia A
 b = Cells(ln + 1, cl).Value 'Leia B
 Cells(ln + 2, cl).Value = a + b 'Exibe [total]
End Sub
Sub Area_do_circulo()
Dim raio As Double 'Declaração Variavel Raio
Dim ln, cl As Integer 'Declaração Constantes ln,cl
ln = 2 'Atribuindo valor p/contante linha
cl = 4 'Atribuindo valor p/contante Coluna
raio = Cells(ln, cl).Value
Cells(ln + 3, cl).Value = 3.14159 * raio * raio
End Sub
Sub Area_do_circulo2()
Dim area, raio As Double 'Declaração das Variaveis Area & Raio
Dim ln, cl As Integer
ln = 2
cl = 4
raio = Cells(ln, cl).Value
area = 3.14159 * raio * raio 'Atribuindo valor p/Variavel Area
Cells(ln + 3, cl).Value = area
End Sub
Sub Area_do_circulo3()
Dim area, raio, PI As Double 'Constante PI é do tipo Double
Dim ln, cl As Integer
ln = 2
cl = 4
PI = 3.14159 'Atribuição de valor p/contante PI
raio = Cells(ln, cl).Value
area = PI * raio * raio
Cells(ln + 3, cl).Value = area
End Sub
Sub Area_do_circulo4()
Dim raio As Double
raio = InputBox("valor do raio", "área do circulo")
MsgBox "o circulo tem " & Chr(13) & area_circulo(raio), ,"Area"
End Sub
Function area_circulo(raio)
area_circulo = 3.14159 * raio ^ 2
End Function
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%
' Algoritmos Resolvidos
'%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Function Diminuir(a, b)
Diminuir = a - b
End Function
Function Dividir(a, b)
Dividir = a / b
End Function
Function Multiplar(a, b)
Multiplar = a * b
End Function
Function elevar(Numero, Expoente) As Double
elevar = Numero ^ Expoente
End Function
Function Calcular_Raiz(Numero, Expoente) As Double
Calcular_Raiz = Numero ^ (1 / Expoente)
End Function
Sub Soma_multi_4_numeros()
Dim a, b, C, D, ln, cl As Integer
ln = 1
cl = 2
a = Cells(ln + 0, cl - 1).Value
b = Cells(ln + 1, cl - 1).Value
C = Cells(ln + 2, cl - 1).Value
D = Cells(ln + 3, cl - 1).Value
Cells(ln + 0, cl + 0).Value = "A + B = " & a + b
Cells(ln + 1, cl + 0).Value = "A + C = " & a + C
Cells(ln + 2, cl + 0).Value = "A + D = " & a + D
Cells(ln + 3, cl + 0).Value
= "B + C = " & b + C
Cells(ln + 4, cl + 0).Value = "B + D = " & b + D
Cells(ln + 5, cl + 0).Value = "D + C = " & D + C
Cells(ln + 0, cl + 1).Value = "A X B = " & b * a
Cells(ln + 1, cl + 1).Value = "A X C = " & C * a
Cells(ln + 2, cl + 1).Value = "A X D = " & D * a
Cells(ln + 3, cl + 1).Value = "B X C = " & C * b
Cells(ln + 4, cl + 1).Value = "B X D = " & b * D
Cells(ln + 5, cl + 1).Value = "D X C = " & C * D
Range("J1").Select
End Sub
Function litros_usados(tempo, velocidade, km_por_lts As Integer)
 litros_usados = (tempo * velocidade) / km_por_lts
End Function
Function Graus_FAHRENHEIT(CELSIUS As Variant)
 Graus_FAHRENHEIT = (9 * CELSIUS + 160) / 5
End Function
Function Graus_CELSIUS(FAHRENHEIT As Variant)
 Graus_CELSIUS = (FAHRENHEIT - 32) * (5 / 9)
End Function
Function Volume_cilindro(raio, altura)
 Volume_cilindro = area_circulo(raio) * altura
End Function
Function Volume_Prisma(raio, altura)
 Volume_Prisma = area(raio) * altura
End Function
Function Volume_Piramede(Area_base, altura)
 Volume_Piramede = (Area_base * altura) / 3
End Function
Function Volume_cone(raio, altura)
 Volume_cone = (area_circulo(raio) * altura) / 3
End Function
Function Volume_Esfera(raio)
 Volume_Esfera = (4 / 3) * (3.14159 * raio ^ 3)
End Function
Function circulo_comprimento(Diametro)
 circulo_comprimento = Diametro * 3.14159
End Function
Function Area_Esfera(raio)
 Area_Esfera = 4 * area_circulo(raio) 'uma função dentro de outra
End Function
Function salario(vlr_hr, hrs_trabalhadas, desconto As Variant)
Dim bruto, vlr_desconto As Variant
 bruto = hrs_trabalhadas * vlr_hr
 vlr_desconto = (desconto / 100) * bruto
 salario = bruto - vlr_desconto
End Function
Function prestação_atrasada(valor, dias_de_atraso, Taxa)
 prestação_atrasada = valor + (valor * (Taxa / 100) * dias_de_atraso)
End Function
Function Hipotenusa(cateto_a, cateto_b)
Dim a, b, C As Integer
 a = cateto_a ^ 2
 b = cateto_b ^ 2
 C = a + b
 Hipotenusa = C ^ 0.5
End Function
Function Enesimo_Termo_da_PA(Quant_de_Termos, Primeiro_Termo, razao)
Enesimo_Termo_da_PA = Primeiro_Termo + (Quant_de_Termos - 1) * razao
End Function
Function Primeiro_Termo_da_PA(Enesimo_termo, Quant_de_Termos, Razão)
Primeiro_Termo_da_PA = Enesimo_termo - (Quant_de_Termos - 1) * Razão
End Function
Function Razão_da_PA(Primeiro_Termo, Enesimo_termo, Quant_de_Termos)
Razão_da_PA = (Enesimo_termo - Primeiro_Termo) / (Quant_de_Termos - 1)
End Function
Function Quant_de_Termos_PA(Primeiro_Termo, Enesimo_termo, Razão)
Quant_de_Termos_PA = (Enesimo_termo - Primeiro_Termo) / Razão + 1
End Function
Function Soma_dos_termos_da_PA(Primeiro_Termo, Quant_termos, razao)
Soma_dos_termos_da_PA = ((Primeiro_Termo + Enesimo_Termo_da_PA _
(Quant_termos, Primeiro_Termo, razao)) * Quant_termos) / 2
End Function
Function Arranjo_simples(maior, Menor)
Arranjo_simples = Fatorial(maior) / Fatorial(maior - Menor)
End Function

Teste o Premium para desbloquear

Aproveite todos os benefícios por 3 dias sem pagar! 😉
Já tem cadastro?

Outros materiais