CIFRAS Y DIVISORES DE UN NUMERO

jueves, 13 de noviembre de 2008

Construya una aplicación que permita el ingreso de un número entero y muestre en pantalla la siguiente información: 1) Cantidad de cifras, 2) Suma de cifras impares, 3) Suma de cifras pares, 4) Suma total de cifras, 5) Cifra mayor, 6) Cifra menor y 7) Divisores de dicho número.

El diseño de la interfaz debe ser similar a la figura siguiente:

Para el desarrollo de esta aplicación, proceda a ubicar los siguientes controles en el formulario:

4 marcos
7 etiquetas
8 cajas de texto
1 botón de comando

En seguida proceda a establecer las propiedades según se indica:

Form1

Nombre
FrmNumeroPerfecto

BorderStyle
3-Fixed Dialog

Caption
Los 3 primeros números perfectos

Moveable
False

StartUpPosition
2-CenterScreen


Frame1

Nombre
FraEntrada

Caption


Frame2

Nombre
FraSalida

Caption


Frame3

Nombre
FraDivisores

Caption
Divisores

Frame4

Nombre
FraSalir

Caption


Label1

Nombre
LblNumero

AutoSize
True

Caption
Ingrese un número:

Label2

Nombre
LblCantCifras

AutoSize
True

Caption
Cantidad de cifras:

Label3

Nombre
LblSumImpares

AutoSize
True

Caption
Suma de cifras impares:

Label4

Nombre
LblSumPares

AutoSize
True

Caption
Suma de cifras pares:

Label5

Nombre
LblSumTotal

AutoSize
True

Caption
Suma total de cifras:

Label6

Nombre
LblCifraMayor

AutoSize
True

Caption
Cifra mayor:

Label7

Nombre
LblCifraMenor

AutoSize
True

Caption
Cifra menor:

Text1

Nombre
TxtNumero

Text


Text2

Nombre
TxtCantCifras

Locked
True

Text


Text3

Nombre
TxtSumImpares

Locked
True

Text

Text4

Nombre
TxtSumPares

Locked
True

Text


Text5

Nombre
TxtSumTotal

Locked
True

Text


Text6

Nombre
TxtCifraMayor

Locked
True

Text


Text7

Nombre
TxtCifraMenor

Locked
True

Text


Text8

Nombre
TxtDivisores

MultiLine
True

Locked
True

ScrollBars
2-Vertical

Text


Command3

Nombre
CmdSalir

Caption
&Salir

Picture
C:\FundVB\Bitmaps\Exit.bmp

Style
1-Graphical

Una vez establecidas las propiedades proceda ha ingresar el código que se indica a continuación:

Private Sub CmdAceptar_Click()
If IsNumeric(TxtNumero) Then
Dim S As Integer, SI As Integer, SP As Integer
Dim May As Integer, Min As Integer
Dim Cad As String
Dim I As Integer, J As Integer
N = CLng(TxtNumero)
M = CLng(TxtNumero)
Cad = “”
I = 0
J = 1
S = SP = SI = 0
For J = 1 To N
If (N Mod J = 0) Then
Cad = Cad & J & vbCrLf
End If
Next J
While (N > 0)
If ((N Mod 10) Mod 2) = 0 Then
SP = SP + (N Mod 10)
Else
SI = SI + (N Mod 10)
End If
S = S + (N Mod 10)
N = N \ 10
I = I + 1
Wend
May = Mid(TxtNumero, 1, 1)
Men = May
While (M > 0)
If May < (M Mod 10) Then
May = M Mod 10
End If
If Men > (M Mod 10) Then
Men = M Mod 10
End If
M = M \ 10
Wend
TxtCantCifras = Str(I)
TxtSumImpares = Str(SI)
TxtSumPares = Str(SP)
TxtSumTotal = Str(S)
TxtCifraMayor = Str(May)
TxtCifraMenor = Str(Men)
TxtDivisores = Cad
Else
MsgBox “Debe ingresar un número”, vbCritical, “Mensaje”
TxtNumero.SetFocus
End If
End Sub

Private Sub CmdSalir_Click()
If MsgBox(“¿Desea terminar la aplicación?”, _
vbQuestion + vbYesNo, "Pregunta") = vbYes Then
End
Else
Cancel = True
TxtNumero.SetFocus
End If
End Sub

0 comentarios: