Answer the question
In order to leave comments, you need to log in
How to check a string for the presence of a digit, if there are no digits write an error and close the program?
func main() {
var num = 0
var summa = 0
var ispos = 0
fmt.Print("Введите число: ")
fmt.Fscan(os.Stdin, &num)
fmt.Println(num)
if num < 0 {
num = num * -1
ispos = -1
fmt.Println(num)
}
for i := 1; i <= num; i++ {
fmt.Println(i)
summa = summa + i
}
if ispos == -1 {
summa = summa * ispos
}
fmt.Println(summa)
}
Answer the question
In order to leave comments, you need to log in
You read a line from a stream.
then
num, err := strconv.Atoi
in num number in err error if string is not a valid number
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question