adding cs142 code

This commit is contained in:
dm
2016-04-06 20:45:34 -07:00
parent 552d456d53
commit 8e52ce1982
174 changed files with 14064 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
package main
import (
"fmt"
"math"
)
const SECONDS_PER_HOUR = 3600
const SECONDS_PER_MINUTE = 60
type time struct {
hours int
minutes int
seconds int
}
func (t time) String() string {
return fmt.Sprintf("%dH:%dM:%dS", t.hours, t.minutes, t.seconds);
}
func int2time(i int) time {
var r_secs int
hours := i / SECONDS_PER_HOUR
r_secs = i % SECONDS_PER_HOUR
mins := r_secs / SECONDS_PER_MINUTE
r_secs = r_secs % SECONDS_PER_MINUTE
return time{hours, mins, r_secs}
}
func main() {
var seconds int
fmt.Print("please enter total seconds: ")
fmt.Scan(&seconds)
fmt.Printf("%v\n", int2time(seconds))
fmt.Printf("%v\n", int2time(int(math.Sqrt(float64(seconds)))))
}