Jump to content
IPS Community Suite 简体中文
Sign in to follow this  
ipscn

Q1

Recommended Posts

已知: 不大于10的所有是3或5的倍数的数字是3,5,6,9, 这四个数字的和是23;
求不大于1000的所有3或5的倍数的总和。


package main

import (
	"fmt"
)

//不支持并发的基础版本
func getIt(maxInt int) int {

	r := 0
	for i := 0; i < maxInt; i++ {

		if i%3 == 0 || i%5 == 0 {
			r += i
		}

	}

	return r
}

func main() {

	maxInt := 1000
	fmt.Println(getIt(maxInt))

}

以上是Go语言的一个解决方案。

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×