Computer Science, asked by lalithagowda556, 6 months ago

write a java program to find the sum of multiples of 3 upto 20 terms using for loop​

Attachments:

Answers

Answered by 0348950
1

Answer:The basic idea is to iterate from i = a to i = n, i++ and check whether i % a == 0 or not.If zero then add i to sum(initially sum = 0).Thus we will get the sum.It will take O(n) time.

We can modify the loop as i = a, i <= n, i = i + a to reduce the number of iterations.But it will also take O(m) time if there is m multiples of a.

Explanation:

Similar questions