Sunday, January 24, 2010

Task 3: Leap year

Now let’s try to make this task.
Make a program to determine whether a year is a leap year or not

Answer:

#include
#include
main()
{
int y;
cout<<"Enter a year: ";
cin>>y;
if (y%4==0)
{cout<<"Leap Year";}
else
{cout<<"Not Leap Year";}
getch();
}

Look at these pictures:




Note:
A leap year is a year that can be divided by 4.
That is mean that the rest of the year divided by for is 0.
In the formula we need to use %. It is the symbol of mod (modulus).
It is used to calculate the rest of divide operation.
For example:
5 % 2 = 1
11 % 4 = 3

0 comments:

Post a Comment