Computer Science, asked by ranichoudhary793, 9 months ago

write a java program to print the sum of the multiples of 3 till n term​

Attachments:

Answers

Answered by fortniteamanid
0

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.

Attachments:
Similar questions