1program sample
2 implicit none
3
4 integer :: year
5
6 ! 標準入力から整数を読み込む
7 write(*, *) 'Input year: '
8 read(*, *) year
9
10 ! 基本的なifによる分岐
11 if(mod(year, 400) == 0) then
12 write(*, *) 'Leap year'
13 else if(mod(year, 100) == 0) then
14 write(*, *) 'Common year'
15 else if(mod(year, 4) == 0) then
16 write(*, *) 'Leap year'
17 else
18 write(*, *) 'Common year'
19 endif
20
21 ! 同じことを入れ子のifで実現
22 if(mod(year, 4) == 0) then
23 if(mod(year, 100) == 0) then
24 if(mod(year, 400) == 0) then
25 write(*, *) 'Leap year'
26 else
27 write(*, *) 'Common year'
28 endif
29 else
30 write(*, *) 'Leap year'
31 endif
32 else
33 write(*, *) 'Common year'
34 endif
35
36 stop
37endprogram sample