Sum of squares of numbers with goroutines
Go
Easy
goroutines
Task «Sum of squares of numbers with goroutines»
Write a Go program that takes an integer n as input, followed by n integers. Create n goroutines, each of which calculates the square of one number. Use a channel to collect the results and output the sum of all squares. It is guaranteed that n > 0 and the numbers do not exceed 1000.
Input Format
First line: integer n (1 ≤ n ≤ 10). Second line: n integers separated by spaces.
Output Format
One integer — the sum of squares of all numbers.
Examples
Example 1
INPUT
1
5
OUTPUT
25
main.go