Created
March 25, 2021 11:18
-
-
Save sidchilling/cee84a799bc060b413f1fadb3dad3c54 to your computer and use it in GitHub Desktop.
Go Routing question
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
package main | |
// Below is a function `sum()` that takes a number, runs a loop to add, and returns the result. | |
// In the main function, we call `sum()` once with a small number (e.g. 1000) and once | |
// with a large number (e.g. 1000000000) and prints the result. After that, the main() | |
// prints the string "All Done!" | |
// Your job is to convert the main() so that we call sum() concurrently, but wait for all the invocations | |
// to sum() to complete before printing "All Done". | |
import ( | |
"fmt" | |
) | |
func sum(num int) int { | |
var res int | |
for i := 1; i <= num; i++ { | |
res += 1 | |
} | |
return res | |
} | |
func main() { | |
fmt.Println(sum(1000000000)) | |
fmt.Println(sum(1000)) | |
fmt.Println("All Done!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment