Ask your own question, for FREE!
Computer Science 9 Online
OpenStudy (itiaax):

Can someone help me with the C code for this? MEDAL WILL BE AWARDED

OpenStudy (itiaax):

Write a program that uses iteration to find the sum of all multiples of 4 and all multiples of 7 between m (inclusive) and n (inclusive) where m and n are two positive integers entered via the keyboard. Assume that m is more than n.

OpenStudy (rsmith6559):

Break it down into the input code, which could be a common function for both m and n. A function to determine if a number is a multiple ( check out the percent operator ).

OpenStudy (itiaax):

:S

OpenStudy (anonymous):

rsmith is right on the money, you can do this! you're iterating so you know you're going to be using a loop, your choice what kind you want to use, so long as the bounds are controlled by the values m and n. Then for each i where m <= i <= n you want to check if it's a multiple with the modulo operator (which is % in a lot of languages) so that if i%4==0 and i%7==0, the value of i is added to some running total. To optimize your execution, you could even start with i = 7 and increment it by 7 at each check, so you really only have to check for divisibility by 4. Once i > n, stop evaluating it and your running total should be exactly what you're looking for.

OpenStudy (itiaax):

Thank you! Now I understand

OpenStudy (anonymous):

Glad to help

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!