Help me, please.
Please make Golang program to find the position of the rightmost number. For example:
There are 10 arrays one dimention
Number: 1 4 7 8 9 2 3 5 3 2
Position: 0 1 2 3 4 5 6 7 8 9
Input the number you want to find the position: 3
Output: The rightmost position of 3 is at index 8
>Solution :
This can be done with a for loop
numbers := // slice of 1 4 7 8 9 2 3 5 3 2
numberToFind := 3
found := false
var position int
for index, number := range numbers {
if number == numberToFind {
found = true
position = index
}
}
if found {
fmt.Println(fmt.Sprintf("found rightmost index of %v at %v", numberToFind, position))
} else {
fmt.Println("number is not in the slice")
}