How to display all even numbers from 1 to 100 in asp.net

In this article I am going to tell you how we can display all even numbers from 1 to 100 in asp.net using C# and Vb.net.

C# code:
  protected void Page_Load(object sender, EventArgs e)
    {
        DispalyEvenNumbers();
    }
    public void DispalyEvenNumbers()
    {
        for (int i = 1; i <= 100; i++)
        {
            if (i % 2 == 0)

            {
                Response.Write(i + "<br/>");
            }
        }
    }
  
VB.net code:
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        DispalyEvenNumbers()
    End Sub
    Public Sub DispalyEvenNumbers()
        For i As Integer = 1 To 100
            If i Mod 2 = 0 Then
                Response.Write(i.ToString() + "<br/>")
            End If
        Next
    End Sub



Post a Comment

0 Comments