Você está na página 1de 15

Programacin II

PROBLEMAS PROPUESTOS
1. Crear una algoritmo que pida un numero de filas y respecto a estas, dibuje lo siguiente:
a)
b)
c)
d)
*
*
*
*

*
**
***
****

Ejemplo para el grafico b):


Datos de entrada
N=5

*
***
*****
*******

Salida

*
***
*****
*******
...

*
**
***
****
*****

a) Private Sub CommandButton1_Click()


Dim n As Integer
n = Hoja1.Cells(4, 2)
For i = 1 To n
Hoja1.Cells(i + 3, 4) = "*"
Next
End Sub

b) Private Sub CommandButton2_Click()


Dim n As Integer
n = Hoja1.Cells(19, 2)
For i = 1 To n
For j = 1 To i
Hoja1.Cells(i + 18, j + 3) = "*"
Next
Next
End Sub

Ing. Juan Carlos Clares Perca

Pagina 1 de 15

Programacin II

c) Private Sub CommandButton3_Click()


Dim n As Integer
n = Cells(35, 2)
For i = 1 To n
For j = 1 To i
x=i+2
Hoja1.Cells(i + 34, j + 3) = "*"
Hoja1.Cells(i + 34, j + x) = "*"
Next
Next
End Sub

d)Private Sub CommandButton4_Click()


Dim n As Integer
n = Hoja1.Cells(46, 2)
For i = 1 To n
For j = 1 To i
If (7 - j) > 0 Then
Hoja1.Cells(i + 45, j + 5) = "*"
Hoja1.Cells(i + 45, 7 - j) = "*"
End If
Next
Next
End Sub

Ing. Juan Carlos Clares Perca

Pagina 2 de 15

Programacin II

2. Leer 6 nmeros e imprimir cuantos son positivos, cuantos negativos y cuantos neutros.
Ejemplo:
Datos de entrada
Numeros: 12 2 0 1 -4 5

Salida
Positivos = 4
Negativos = 1
Neutros = 1

Private Sub CommandButton1_Click()


Dim nums(1 To 6) As Integer
For i = 1 To 6
nums(i) = Hoja2.Cells(5, i + 1)
Next
neutros = 0
positivos = 0
negativos = 0
For i = 1 To 6
If nums(i) = 0 Then
neutros = neutros + 1
End If
If nums(i) < 0 Then
negativos = negativos + 1
End If
If nums(i) > 0 Then
positivos = positivos + 1
End If
Next
Hoja2.Cells(8, 2) = positivos
Hoja2.Cells(9, 2) = negativos
Hoja2.Cells(10, 2) = neutros
End Sub

Ing. Juan Carlos Clares Perca

Pagina 3 de 15

Programacin II

3. Lea N nmeros e indique el mayor


Ejemplo:
Datos de entrada
N=7
Numeros: 7 4 2 4 9 10 5

Salida
Mayor numero = 10

Private Sub CommandButton1_Click()


Dim nums(1 To 100) As Integer
n = Hoja3.Cells(5, 2)
For i = 1 To n
nums(i) = Hoja3.Cells(7, i + 1)
Next
mayor = nums(1)
For i = 1 To n
If mayor < nums(i) Then
mayor = nums(i)
End If
Next
Hoja3.Cells(10, 2) = mayor
End Sub

Ing. Juan Carlos Clares Perca

Pagina 4 de 15

Programacin II

4. Suponga que se tiene un conjunto de calificaciones de un grupo de 20 alumnos. Realizar un


algoritmo para calcular la calificacin media y la calificacin ms baja y la calificacin ms alta
de todo el grupo.
Ejemplo:
Datos de entrada (ingresar las veinte calificaciones)
Calificaciones: 11 10 13 05 07 12 16 15 12 15 20 19 09 14 15 16 10 12 19 16
Salida
Calificacion_media = 13.33
Calificacion_alta = 20
Calificacion_baja = 5
Private Sub CommandButton1_Click()
Dim nums(1 To 100) As Integer
columna = 2
For i = 1 To 20
If (i <= 10) Then
nums(i) = Hoja4.Cells(7, i + 1)
Else
nums(i) = Hoja4.Cells(8, columna)
columna = columna + 1
End If
Next
nota_alta = nums(1)
nota_baja = nums(1)
suma = 0
For i = 1 To 20
suma = suma + nums(i)
If nota_alta < nums(i) Then
nota_alta = nums(i)
End If
If nota_baja > nums(i) Then
nota_baja = nums(i)
End If
Next
Hoja4.Cells(10, 2) = suma / 20
Hoja4.Cells(11, 2) = nota_alta
Hoja4.Cells(12, 2) = nota_baja
End Sub

Ing. Juan Carlos Clares Perca

Pagina 5 de 15

Programacin II

5. Calcular:

S = 1! + 3!+5! + 7!+ ... + N!

N= nmero impar

Ejemplo:
Datos de entrada
N=7
Salida
S=5164
Private Sub CommandButton1_Click()
Dim nums(1 To 100) As Double
Dim n As Integer
n = Hoja5.Range("b" & 5).Value
factorial = 1
For i = 1 To n
factorial = factorial * i
nums(i) = factorial
Next
suma = 0
For i = 1 To n Step 2
suma = nums(i) + suma
Next
Hoja5.Range("b" & 7).Value = suma
End Sub

Ing. Juan Carlos Clares Perca

Pagina 6 de 15

Programacin II

6. Calcular:

S = 1/2! + 22/4! + 33/6!+ ... + NN/(2N)!

Ejemplo:
Datos de entrada
N=5
Salida
S=0.71
Private Sub CommandButton1_Click()
Dim a(1 To 100) As Double
Dim b(1 To 100) As Double
Dim c(1 To 100) As Double
Dim d(1 To 100) As Double
Dim n As Integer
n = Hoja6.Cells(7, 2)
factorial = 1
For i = 1 To 2 * n
factorial = factorial * i
a(i) = factorial
Next
For i = 1 To n
c(i) = i ^ i
Next
i = 1
For j = 1 To 2 * n
If (j Mod 2 = 0 Or a(i) = 1) Then
b(i) = a(j)
i = i + 1
End If
Next
j = 1
For i = 1 To n + 1
If i > 1 Then
d(j) = c(j) / b(i)
j = j + 1
End If
Next
suma = 0
For i = 1 To n
suma = suma + d(i)
Next
Hoja6.Range("b" & 9).Value = suma
End Sub

Ing. Juan Carlos Clares Perca

Pagina 7 de 15

Programacin II

7. Calcule la suma de la siguiente serie:


Ejemplo:
Datos de entrada
X=6
N=5
Datos de salida
S = 178.8
Private Sub CommandButton1_Click()
Dim a(1 To 100), b(1 To 100), c(1 To 100)
As Double
Dim n, x As Integer
x = Cells(7, 2)
n = Cells(8, 2)
For i = 1 To n
a(i) = 6 ^ (i)
Next
fac = 1
For i = 1 To n
fac = fac * i
b(i) = fac
Next
For i = 1 To n
c(i) = a(i) / b(i)
Next
suma = 0
For i = 1 To n
suma = suma + c(i)
Next
Cells(10, 2) = suma
End Sub

Ing. Juan Carlos Clares Perca

Pagina 8 de 15

Programacin II

8. De cuantas maneras podemos tomar r


elementos de un total de n elementos? (n r).
(

Private Sub CommandButton1_Click()


Dim a(1 To 100) As Integer
Dim n As Integer
Dim r As Integer
n = Cells(7, 2)
r = Cells(8, 2)
tope = n - r
nfac = 1
For i = 1 To n
nfac = nfac * i
Next
rfac = 1
For i = 1 To r
rfac = rfac * i
Next
nrfac = 1
For i = 1 To tope
nrfac = nrfac * i
Next
demfac = rfac * nrfac
Cells(10, 2) = nfac / demfac
End Sub

Ing. Juan Carlos Clares Perca

Pagina 9 de 15

Programacin II

9. Calcular X:

Private Sub CommandButton1_Click()


Dim n, a, b As Integer
Dim y(1 To 100) As Integer
Dim z(1 To 100) As Integer
n = Cells(15, 2)
a = Cells(15, 2)
b = Cells(15, 2)
amb = a - b
suma = 0
For i = 1 To n
y(i) = ((amb ^ (i)) - 3) + n
suma = suma + y(i)
Next
producto = 1
For j = 2 To (n - 1)
z(i) = (2 + (a * (j - 1)))
producto = producto * z(i)
Next
Cells(19, 2) = suma / producto
End Sub

Ing. Juan Carlos Clares Perca

Pagina 10 de 15

Programacin II
TABLA DE MULTIPLICAR

10. Muestre la tabla de multiplicar del 1 al 10

Private Sub CommandButton1_Click()


Dim a(1 To 100) As Integer
Dim b(1 To 100) As Integer
k=1
f=5
For i = 1 To 10
For j = 1 To 10
If k = 5 Then
k=1
End If
Cells(f, k) = i
k=k+1
Cells(f, k) = "x"
k=k+1
Cells(f, k) = j
k=k+1
Cells(f, k) = "="
k=k+1
Cells(f, k) = (i * j)
f=f+1
Next
Next
End Sub

Ing. Juan Carlos Clares Perca

1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2

x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x

1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10

=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=

1
2
3
4
5
6
7
8
9
10
2
4
6
8
10
12
14
16
18
20

Pagina 11 de 15

Programacin II

11. Encuentre todos los nmeros primos de 3 dgitos


Private Sub CommandButton1_Click()
Dim a(1 To 500), b(1 To 500) As Byte
k=1
cant = 0
primos = 1
For i = 1 To 100
For j = 1 To 15
division = i Mod 2
If i / 2 >= 1 Then
a(k) = division
End If
Next
For l = 1 To k
cant = cant + a(k)
Next
If cant Mod 2 >= 0 Then
primos = primos + 1
End If
k=k+1
Next
For i = 1 To k - 1
Cells(13, i) = i
Cells(14, i) = a(i)
Next

cant = 0
For i = 1 To k - 1
If a(i) = 1 Then
cant = cant + 1
End If
Next
Cells(16, 2) = cant
Cells(17, 2) = primos
End Sub

Ing. Juan Carlos Clares Perca

Pagina 12 de 15

Programacin II

12. Visualizar en un solo programa cualquiera de los casos segn eleccin:


Caso A)
1
1
1
..
..
1

2
2

...

Caso B)

1
2

..

1
2
3
..
..
N

Caso C)

1
2

..

1
1
...
...
1
1

2
2

3
3

..

Ejemplo:
Datos de entrada
N=5
Opcion=B
Salida
1
121
12321
1234321
123454321

Private Sub CommandButton1_Click()


Dim op As String
Dim n As Integer
n = Cells(6, 2)
op = Cells(7, 2)
f = 30
If (op = "A" Or op = "a") Then
For i = 1 To n
For j = 1 To i
If j <= i Then
Cells(i + 8, j) = j
End If
Next
Next
ElseIf op = "B" Or op = "b" Then
For i = 1 To n
For j = 1 To i
If (i - j) <> 0 And 9 - j > 0 Then
Cells(i + 8, j + 7) = i - j
Cells(i + 8, 9 - j) = i - j
End If
Next
Next
ElseIf op = "C" Or op = "c" Then
For i = 1 To n
For j = 1 To i
If f > 0 Then 'fila hacia arriba
If j >= i Then
Cells(f, j) = j

Ing. Juan Carlos Clares Perca

Pagina 13 de 15

Programacin II

f=f-1
Else
Cells(f, j) = j
End If
End If
Next
Next
End If
'd
End Sub

Ing. Juan Carlos Clares Perca

Pagina 14 de 15

Programacin II

NOMBRE: Hebert Jonatan

APELLIDOS: Vilca Mamani

CURSO: Programacion II

CODIGO: 131081011P

CARRERA: Ingeniera de Sistemas e


Informtica

Ing. Juan Carlos Clares Perca

Pagina 15 de 15

Você também pode gostar