forked from inancgumus/learngo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8aac2c
commit 60fd45c
Showing
10 changed files
with
283 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// For more tutorials: https://blog.learngoprogramming.com | ||
// | ||
// Copyright © 2018 Inanc Gumus | ||
// Learn Go Programming Course | ||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ | ||
// | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
) | ||
|
||
func main() { | ||
var ( | ||
radius = 10. | ||
area float64 | ||
) | ||
|
||
area = math.Pi * radius * radius | ||
|
||
fmt.Printf("radius: %g -> area: %.2f\n", | ||
radius, area) | ||
|
||
// ALTERNATIVE: | ||
// math.Pow calculates the power of a float number | ||
// area = math.Pi * math.Pow(radius, 2) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// For more tutorials: https://blog.learngoprogramming.com | ||
// | ||
// Copyright © 2018 Inanc Gumus | ||
// Learn Go Programming Course | ||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ | ||
// | ||
|
||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
celsius := 35. | ||
|
||
// Wrong formula : 9*celsius + 160 / 5 | ||
// Correct formula: (9*celsius + 160) / 5 | ||
fahrenheit := (9*celsius + 160) / 5 | ||
|
||
fmt.Printf("%g ºC is %g ºF\n", celsius, fahrenheit) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// For more tutorials: https://blog.learngoprogramming.com | ||
// | ||
// Copyright © 2018 Inanc Gumus | ||
// Learn Go Programming Course | ||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/ | ||
// | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
) | ||
|
||
func main() { | ||
// var counter int | ||
// var factor float64 | ||
var ( | ||
counter int | ||
factor float64 | ||
) | ||
|
||
// counter = counter + 1 | ||
counter++ | ||
fmt.Println(counter) | ||
|
||
// counter = counter - 1 | ||
counter-- | ||
fmt.Println(counter) | ||
|
||
// counter = counter + 5 | ||
counter += 5 | ||
fmt.Println(counter) | ||
|
||
// counter = counter * 10 | ||
counter *= 10 | ||
fmt.Println(counter) | ||
|
||
// counter = counter / 2.0 | ||
counter /= 2.0 | ||
fmt.Println(counter) | ||
|
||
factor += float64(counter) | ||
fmt.Println(counter) | ||
|
||
var bigCounter int64 | ||
counter += int(bigCounter) | ||
fmt.Println(counter) | ||
|
||
fmt.Println( | ||
"hello" + ", " + "how" + " " + "are" + " " + "today?", | ||
) | ||
|
||
// you can combine raw string and string literals | ||
fmt.Println( | ||
`hello` + `, ` + `how` + ` ` + `are` + ` ` + "today?", | ||
) | ||
|
||
// ------------------------------------------ | ||
// Converting non-string values into string | ||
// ------------------------------------------ | ||
|
||
eq := "1 + 2 = " | ||
sum := 1 + 2 | ||
|
||
// invalid op | ||
// string concat op can only be used with strings | ||
// fmt.Println(eq + sum) | ||
|
||
// you need to convert it using strconv.Itoa | ||
// Itoa = Integer to ASCII | ||
|
||
fmt.Println(eq + strconv.Itoa(sum)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
) | ||
|
||
func main() { | ||
c, _ := strconv.ParseFloat(os.Args[1], 64) | ||
f := c*1.8 + 32 | ||
|
||
// Like this: | ||
fmt.Printf("%g ºC is %g ºF\n", c, f) | ||
|
||
// Or just like this (both are correct): | ||
fmt.Printf("%g ºF\n", f) | ||
} |
Oops, something went wrong.