Last active
May 10, 2017 13:38
-
-
Save artivnv/1d55797eb09097d9040235518b51e73f to your computer and use it in GitHub Desktop.
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 | |
import "fmt" | |
func main() { | |
var n, a int | |
for { | |
fmt.Print("Введите число: ") | |
_, err := fmt.Scanln(&n) | |
if err != nil { | |
var discard string | |
fmt.Scanln(&discard) | |
fmt.Println("Ошибка. Введите значение типа int!") | |
} else { | |
break | |
} | |
} | |
numbers := []int{1, 2, 6, 4, 5, 7, 8, 9, 5, 6, 3, 1, 5, 7, 2, 8, 4, 6, 7, 8, 3, 4, 2, 5} | |
min := &numbers[0] // получаем адрес переменной | |
max := &numbers[0] | |
for _, number := range numbers { | |
if number == n { | |
a++ | |
} | |
} | |
for i, _ := range numbers { | |
if *min > numbers[i] { //если участок памяти где хранится значение min > номер текущего элемента массива | |
min = &numbers[i] | |
} else if *max < numbers[i] { | |
max = &numbers[i] | |
} | |
} | |
fmt.Println("Таких чисел в массиве", a, "шт.") | |
fmt.Println("Минимальное число массива:", *min) | |
fmt.Println("Максимальное число массива:", *max) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment