Chal001 - Golang


list all the natural numbers below 10 that are multiples of 3 or 5

Side columns

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23

Find the sum of all the multiples of 3 or 5 below 1000.”

put answer here

THis is a short code

package main

import "fmt"

func main() {
	sum := 0
	tn := 1000
	fmt.Println(" hi there")

	for i := 0; i < tn; i++ {
		if i%3 == 0 || i%5 == 0 {
			sum += i
		}
	}

	fmt.Println("the sum of these numbers is", sum)

}

See also


vyDiagnostics here


title: Chal001 - Golang

Type: chal