Desarrolle un algoritmo que lea los primeros 300 números enteros y determine cuántos
de ellos son impares; al final deberá indicar su sumatoria
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 sum As Integer = 0 Dim cont As Integer = 0 Dim cad As String = "" For i As Integer = 1 To 300 If (i Mod 2 <> 0) Then sum = sum + i cont = cont + 1 cad = cad + " - " + Trim(i) End If Next i TextBox1.Text = cad TextBox2.Text = "La suma es " + Trim(sum) + " hay " + Trim(cont) + " numeros impares" End Sub
0 comentarios:
Publicar un comentario