fix: loops exercises odd number sum problem

This commit is contained in:
Inanc Gumus
2018-11-21 11:42:33 +03:00
parent eb2b926264
commit df688c0cb6
4 changed files with 9 additions and 8 deletions

View File

@ -19,7 +19,7 @@ func main() {
sum += i
fmt.Print(i)
if i != max {
if i < max {
fmt.Print(" + ")
}
}

View File

@ -31,7 +31,7 @@ func main() {
sum += i
fmt.Print(i)
if i != max {
if i < max {
fmt.Print(" + ")
}
}

View File

@ -34,7 +34,7 @@ func main() {
sum += i
fmt.Print(i)
if i != max {
if i < max-1 {
fmt.Print(" + ")
}
}

View File

@ -32,18 +32,19 @@ func main() {
)
for {
if i%2 != 0 {
if i > max {
break
} else if i%2 != 0 {
i++
continue
}
sum += i
fmt.Print(i)
if i != max {
if i < max-1 {
fmt.Print(" + ")
} else {
break
}
sum += i
i++
}
fmt.Printf(" = %d\n", sum)