題目

找出1~輸入數字區間中3和5的倍數加起來返回

思路

循環一次數字區間檢查是不是3或5的倍數

程式碼

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public static class Kata
{
public static int Solution(int value)
{
int ans = 0;
if(value <= 0 ) return 0;
for(int i = 1; i < value ; i++){
if(i % 3 == 0 || i % 5 == 0){
ans += i;
}
}
return ans ;
}
}

改進的地方