Arrays
-
Implement a function
func maxMin(arr [10]int) (max, min int)
that returns the maximal and minimal numbers from the array. -
Implement a function
func countMax(arr [10]int) (count, first uint)
that calculates how many times the maximal value is present in the array (returned as a variablecount
) and an index of the first occurrence (returned as a variablefirst
). -
Implement a function
func posNegZeros(arr [10]int) (pos, neg, zeros uint)
that calculates and returns the number of positive (pos
), negative (neg
) and zeros (zeros
) in the array. -
Implement a function
func eqArrays(a, b [10]int) (uint, uint)
that checks if two arrays are equal. The first return value must be equal to1
, if the arrays are equal, and0
, otherwise. If they are not equal, the second return value must contain the first index of unequal elements. -
Implement a function
func printInColumns(arr [10]int)
that prints elements of the input array in two columns: the first column contains positive values, the second column contains other values.Example:
func printInColumns([10]int{2, 3, -5, 1, -1, 0, 3}) prints |-----|-----| | 2 | | | 3 | | | | -5 | | 1 | | | | -1 | | | 0 | | 3 | | |-----|-----|
Improve the function so it prints the columns as follows:
func printInColumns([10]int{2, 3, -5, 1, -1, 0, 3}) prints |-----|-----| | 2 | -5 | | 3 | -1 | | 1 | 0 | | 3 | | |-----|-----|
-
Implement a function
func distinctNumbers(arr [10]int) uint
that returns the number of distinct numbers in the array. -
Implement a function
func isPermutation(arr [10]int) uint
that returns1
if the array is a permutation of integer numbers from 1 to N, and0
, otherwise. -
Implement a function
func partition(arr [10]int, p uint) [10]int
that returns an array consisting of the elements inarr
, where all elements that are less thanp
come first, then all elements that are equal top
, and then all elements that are greater thanp
. -
Let
a [10]int
andb [10]int
be arrays that represent “long” non-negative integers, Every element of the array stores a single digit in the number. E.g.[10]int{0, 0, 2, 0, 1, 9, 2, 0, 2, 0}
represents a number20192020
. Implement a functionfunc sum(a, b [10]int) [11]int
that sums two “long” numbers. -
Let $n$ and $m$ be natural numbers, such that $0 < n < m$. Write a program that prints a fraction as a periodic decimal fraction. For example, $27/70=0.3(857142)$, $17/25 = 0.68$.