0% found this document useful (0 votes)
24 views4 pages

Solucionario de Los Ejercicios 13, 14, 15 Alumnos

This document contains code for 3 exercises: Exercise 13 checks if a number is prime by testing if it is only divisible by 1 and itself. Exercise 14 displays the first n prime numbers by testing numbers from 2 to n for divisibility and adding qualifying numbers to a list. Exercise 15 displays the first n perfect numbers by testing numbers for divisibility by previous numbers and summing the results, adding numbers where the sum equals the number.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views4 pages

Solucionario de Los Ejercicios 13, 14, 15 Alumnos

This document contains code for 3 exercises: Exercise 13 checks if a number is prime by testing if it is only divisible by 1 and itself. Exercise 14 displays the first n prime numbers by testing numbers from 2 to n for divisibility and adding qualifying numbers to a list. Exercise 15 displays the first n perfect numbers by testing numbers for divisibility by previous numbers and summing the results, adding numbers where the sum equals the number.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

SOLUCIONARIO DE LOS EJERCICIOS 13, 14, 15

ALUMNOS:

- SIFUENTES SIFUENTES JOEL DAVID

- CRUZ TAPIA SHUMAGER PASCUAL

- VALENZUELA AGUIRRE ISMAEL


EJERCICIO 13:
Public Class Form1

Private Sub btnverificar_Click(sender As Object, e As EventArgs) Handles


btnverificar.Click
Dim a As Integer = 0
Dim n As Integer
n = txtnum.Text
For i As Integer = 1 To n + 1
If (n Mod i = 0) Then
a = a + 1
End If
Next i
If (a <> 2) Then
txtres.Text = "EL NUMERO NO ES UN NUMERO PRIMO"
Else
txtres.Text = "EL NUMERO SI ES UN NUMERO PRIMO"
End If
End Sub

Private Sub btnnuevo_Click(sender As Object, e As EventArgs) Handles


btnnuevo.Click
txtnum.Clear()
txtres.Clear()
Me.txtnum.Focus()
End Sub

Private Sub btncerrar_Click(sender As Object, e As EventArgs) Handles


btncerrar.Click
End
End Sub
End Class
EJERCICIO 14
Public Class Form1

Private Sub btnver_Click(sender As Object, e As EventArgs) Handles btnver.Click


Dim num, c, cd, i, n As Integer

c = 1
n = Val(txtprimos.Text)
num = 2

Do While c <= n

cd = 0
For i = 1 To num
If num Mod i = 0 Then
cd = cd + 1
End If
Next
If cd = 2 Then
lstprimos.Items.Add(c & "" & " " & num)
c = c + 1
End If
If (c >= n) Then

End If
num = num + 1
Loop
End Sub
End Class
EJERCICIO 15
Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles


Button1.Click
lstperfecto.Items.Clear()
Dim num, c, cd, n, suma, i As Integer
c = 1
n = Val(txtnumero.Text)
num = 0
suma = 0
Do While c <= n
cd = 0
For i = 1 To num - 1
If num Mod i = 0 Then
cd = cd + 1
suma = suma + 1
End If
Next
If suma = n Then
lstperfecto.Items.Add(c & "" & num)
c = c + 1
End If
If (c >= n) Then

End If
Loop
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles


Button2.Click
End
End Sub
End Class

You might also like