Anonymous user
Find the last Sunday of each month: Difference between revisions
Find the last Sunday of each month (view source)
Revision as of 21:01, 14 November 2014
, 9 years ago→{{header|Go}}: changed input method and typo
(→{{header|Go}}: changed input method and typo) |
|||
Line 529:
This is different from the Go code for [[Last Friday of each month]]. It uses the fact that time functions in Go correct for dates: if you enter 32nd of october, Go corrects to 1st of November. So that if 29th of February is corrected to 1st of March, chosen year is not a leap year.
<lang
import (
"fmt"
"time"
)
func main() {
var
var t time.Time
var lastDay = [12]int { 31,29,31,30,31,30,31,31,30,31,30,31 }
for {
_, err := fmt.Scanf("%d", &year)
if err != nil {
fmt.Println(err)
continue
break▼
} else {
▲ break
}
}
fmt.Println("Last Sundays of each month of", year)
Line 577 ⟶ 574:
}
}
}
</lang>
|