ADVERTISEMENT
ADVERTISEMENT

VB.Net program to check leap year

Here, we are going to learn how to check leap year in VB.Net?
Submitted by Nidhi, on December 02, 2020

Here, we will read a year from the user and then find the given year is a leap year or not and then print the appropriate message on the console screen.

Program/Source Code:

The source code to check the entered year is a leap year or not is given below. The given program is compiled and executed successfully.

'VB.Net program to check the given year is a leap year or not. 

Module Module1

    Sub Main()
        Dim year As Integer = 0
        
        Console.Write("Enter year: ")
        year = Integer.Parse(Console.ReadLine())

        If ((year Mod 4 = 0) AndAlso (year Mod 100 <> 0)) OrElse ((year Mod 4 = 0) AndAlso (year Mod 100 = 0) AndAlso (year Mod 400 = 0)) Then
            Console.WriteLine("Entered year is leap year")
        Else
            Console.WriteLine("Entered year is not leap year")
        End If
    End Sub
    
End Module

Output:

Enter year: 2004
Entered year is leap year
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1 that contains a method Main(). In the Main() method, we created an integer variable year with an initial value 0.

Console.Write("Enter year: ")
year = Integer.Parse(Console.ReadLine())

Here, we read the value of variable year from user.

If ((year Mod 4 = 0) AndAlso (year Mod 100 <> 0)) OrElse 
((year Mod 4 = 0) AndAlso (year Mod 100 = 0) AndAlso (year Mod 400 = 0)) Then
    Console.WriteLine("Entered year is leap year")
Else
    Console.WriteLine("Entered year is not leap year")
End If

Here, we use if statements to check given year is leap year or not, and then we printed appropriate message on the console screen.

VB.Net Basic Programs »



ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.