Calculate the sum of numbers divisible both by 3 and 5, between ‘m’ and ‘n’ both inclusive and return the same
Write a function "calculateSum" that accepts two integers m and n and returns the sum of numbers divisible by both 3 and 5. ( m<n)
Java
1 2 3 4 5 6 7 8 | public static int calculateSum(int m, int n){ int sum = 0; for(int i=m; i<=n; i++){ if(i%3==0 && i%5==0) sum += i; } return sum; } |
Python
def calculateSum(m, n): sum = 0 for i in range(m,n+1): if i%3==0 and i%5==0: sum += i return sum |