Visual basic program to check leap year or not

How to Write a visual basic program to check leap year or whether a year is leap year or not a leap year.

Module Module1
     Sub Main()
        Console.WriteLine("Enter a year...")
        Dim x, y, z, year
        'Read a year..........
        year = Console.ReadLine()
        x = year Mod 4
        y = year Mod 100
        z = year Mod 400
        If ((x = 0 And Not (y = 0)) Or z = 0) Then
            Console.WriteLine("This is a leap year")
        Else
            Console.WriteLine("This is not a leap year")
 
        End If
        Console.ReadLine()
    End Sub
 
End Module

Output:

Check leap year in visual basic using forms

This example will contain the example to check a year is leap year or not in visual basic.

Public Class Form1
     Dim x, y, z, year
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Sum.Click
        year = TextBox1.Text
        x = year Mod 4
        y = year Mod 100
        z = year Mod 400
        If ((x = 0 And Not (y = 0)) Or z = 0) Then
            Label2.Text = "This is a leap year"
        Else
            Label2.Text = "This is not a leap year"
        End If
    End Sub
 
End Class

Output

Add a Comment

Your email address will not be published. Required fields are marked *

4 × 3 =