write a java program to find the sum of multiples of 3 upto 20 terms using for loop
Attachments:
Answers
Answered by
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
Environmental Sciences,
2 months ago
Science,
2 months ago
Computer Science,
2 months ago
Biology,
4 months ago
Math,
4 months ago
English,
9 months ago
Math,
9 months ago