Pages

viernes, 25 de enero de 2013

Calcular suma de números pares e impares entre 1 y 50 Codigo Fuente en Visual Basic

Problema
Hacer un programa o algoritmo, que calcule independientemente la suma de los números pares e impares comprendidos entre 1 y 50.

Codigo Fuente en Visual Basic
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles Button1.Click
        Dim cad As String = ""
        Dim sal As String = ""
        Dim sump As Integer = 0
        Dim sumi As Integer = 0
        For i As Integer = 1 To 25
            cad = cad + " " + Trim(2 * i)
            sal = sal + " " + Trim(2 * i - 1)
            sump = sump + (2 * i)
            sumi = sumi + (2 * i - 1)
        Next
        TextBox1.Text = cad
        TextBox2.Text = sal
        TextBox3.Text = "Suma impares:" +
        Trim(sumi) + " Suma pares: " + Trim(sump)
    End Sub
End Class

2 comentarios: