The algorithm or logic for Leap year is basically that:
1. A year is a leap year if it is divisible by 4 but not by 100.
2. If a year is divisible by both 4 and by 100, then it can only be a leap year if it is also divisible by 400.
<html>
<head>
<body>
<script language="javascript">
var x=prompt("hello "," ");
if(x%4 == 0 && x%100 == 0)
{
if(x%400 == 0)
alert("leap year");
else
alert("not leap year");
}
else
{
if(x%4 == 0 && x%100 != 0)
alert("leap year");
else
alert("not leap year");
}
</script>
</body>
</html>
Save the program in notepad as leapyear.html and open in any browser.
1. A year is a leap year if it is divisible by 4 but not by 100.
2. If a year is divisible by both 4 and by 100, then it can only be a leap year if it is also divisible by 400.
<html>
<head>
<body>
<script language="javascript">
var x=prompt("hello "," ");
if(x%4 == 0 && x%100 == 0)
{
if(x%400 == 0)
alert("leap year");
else
alert("not leap year");
}
else
{
if(x%4 == 0 && x%100 != 0)
alert("leap year");
else
alert("not leap year");
}
</script>
</body>
</html>
Save the program in notepad as leapyear.html and open in any browser.
No comments:
Post a Comment