This program determines if a year is a leap year or not. A leap year is divisible by 4 but not by 100, except when it is divisible by 400. A number x is divisible by a number y if the remainder
of x/y is identical to zero, i.e. *Rem(x/y}*=O is true therefore

Leap Year = {*Rem* (Year/4) = 0 And Not (*Rem* (Year/100) = 0)} Or *Rem* (Year/400) = 0 (3.1)

where And, Or and Not are Boolean operators.

For example:

1900 is not a leap year because it is divisible by 100

1970 is not a leap year because it is not divisible by 4

1980 is a leap year because it is divisible by 4 but not by 100

2000 is a leap year because it is divisible by 400

Start a new G program and right click on the Block Diagram window. Go to the **Functions** » **Pro****gramming** »
**Numeric** menu in the Block Diagram window.

Select three copies of the **Quotient & Remainder** function and three numeric constants. Type in 4, 100 and 400 for the numeric constants and wire these constants
to the lower input terminal (corresponding to the dividend) of the **Quotient & Remainder** function.

From the **Functions** » **Programming** » **Comparison** menu, select 2 copies of the **Equal
to Zero** function and one copy of the **Not Equal to Zero** function.

Organize the comparison operations as show in the diagram.

From the **Functions** » **Programming** » **Boolean** menu select the **AND** and
**OR** operators

Place the Boolean operators as shown in Q&R, Comparison & Boolean Functions.

From the **Functions** » **Programming** » **Structures** menu, click on the **Case
Structure**.

Click and drag on the Block Diagram window to create the **Cas****e Structure**.

The **Tru****e** diagra m option is indicated at the top of the case structure.

Drop a string constant and type "Is a Leap Year".

Click on the down arrowhead next to the **Tru****e** label and select the **Fals****e**
option .

Drop another string constant and type "Is not a Leap Year".

Go to the Front Panel window and place a numeric input and an output string. Re-label the numeric input to **Year** and the output string to **Message**.

Right click on **Year** and select **Representation** » **I3****2** from the numeric
pop-up menu.

Arrange the **Year** and **Message** terminals in the Block Diagram window as shown in the figure.

Wire the **OR** operator is to the "7" in the case structure and the string constant "Is not a Leap Year" is wired to **Message**.

Select the **True** option and Wire the "Is a Leap Year" string constant to the output terminal of the **Case Structure**.

Save the program as **Leap Year.vi**, enter**Year** values and run the program to determine whether the value of **Year** is that of a leap year or not.

- 1427 reads