ViijayScript: #Program to #Check #Leap #Year in #C #C++ C# #Java #Python #Updated on 2017

Sunday, 15 October 2017

#Program to #Check #Leap #Year in #C #C++ C# #Java #Python #Updated on 2017

Hello netizens, On this post I am going to tell #Programs to #check #leap #year in #C #C++ #Java C# #Python.

Program in C:

#include <stdio.h>
int main()
{
int year;
printf(“Enter a year to check if it is a leap year\n”);
scanf(“%d”, &year);
if ( year%100 == 0)
{
if ( year%400 == 0)
printf(“%d is a leap year.\n”, year);
else
printf(“%d is not a leap year.\n”, year);
}
else if ( year%4 == 0 )
printf(“%d is a leap year.\n”, year);
else
printf(“%d is not a leap year.\n”, year);
return 0;
}

Program in C++:

#include <iostream>
using namespace std ;
int main ()
{
int year ;
cout <> year ;
if ( ( year % 400 == 0 || year % 100 != 0 ) &&( year % 4 == 0 ))
cout << "It is a leap year" ;
else
cout << "It is not a leap year" ;
return 0 ;
}

Program in Java:

public class LeapYear { public static void main(String[] args) {
int year = Integer.parseInt(args[0]);
if ( year%100 == 0)
{
if ( year%400 == 0)
System.out.println(year+“ is a leap year."+year);
else
System.out.println(year+“ is not a leap year.”+year);
}
if( year%4 == 0 )
System.out.println(year+“is a leap year.”+year);
else
System.out.println(year+“ is not a leap year.”+year);
}
}

Program in C#:

1. /*
2. C# Program to Check Whether the Entered Year is a Leap Year or Not
3. */
4. using System ;
5. using System.Collections.Generic ;
6. using System.Linq ;
7. using System.Text ;
8.
9. namespace Program
10. {
11. class leapyear
12. {
13. static void Main (string [] args )
14. {
15. leapyear obj = new leapyear ();
16. obj.readdata ();
17. obj.leap ();
18. }
19. int y ;
20. public void readdata ()
21. {
22. Console.WriteLine ( “Enter the Year in Four Digits : ” );
23. y = Convert .ToInt32 ( Console.ReadLine ());
24. }
25. public void leap ()
26. {
27. if (( y % 4 == 0 && y % 100 != 0 ) || ( y
% 400 == 0 ))
28. {
29. Console . WriteLine (“{0} is a Leap Year” , y );
30. }
31. else
32. {
33. Console . WriteLine (“{0} is not a Leap Year” , y );
34. }
35. Console.ReadLine ();
36. }
37. }
38. }

Program in Python:

def IsLeapYear(year):
if((year % 4) == 0):
if((year % 100) == 0):
if( (year % 400) == 0):
return 1
else:
return 0
else:
return 1
return 0 n = 0
print “Program to check Leap Year”
print “Enter Year: “, n = input()
if( IsLeapYear(n) == 1):
print n, “is a leap year”
else:
print n, “is NOT a leap year”

If our post is helpful then share it with your near and dear ones.

No comments:

Post a Comment

Prove that you are Alive by Writing Comments

Scan this QR Code on LinkedIn

Scan this QR Code on LinkedIn