Homework help

Write your question here.
Include the use of ++, += in a program that achieves the following using loops.
(You can do these in
one program or each one in a small program, it doesn’t
matter.)
(20 points each)
A.
Create a
loop that wi
ll output all the multiples of 5
that are
greater than zero and
less than
60 (do not include 60)
.
5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55
B.
Create a loop that will out
put all the numbers less than 200 that are evenly
divisible by both 2 and 7.
14 28 ...
C.
Create a loop that will calcula
te the sum of the multiples of 8
that are between 100
and 500. Output the sum
only
.
D.
Create a loop that will output the sum of all odd numbers between 2
0
and 100
.
honestly not sure how to start
the syntax of a for loop is

for(precondition, loop condition (while true, effectively), operation each loop)

or, a basic example
for(int x = 0; x < 10; x++) //create x and initialize it once, while its < 10, add 1 every loop iteration (++ adds one)

----------------------
+= is shorthand for
x = x+y;
so the same thing is
x += y;

you can do any basic math operation with those.. +=, *=, /=, %=, etc

so for A... 5*12 is 60.
you need 5*1, 5*2, ... 5*11 and stop.
can you make a loop for that now?
hint.. in the example loop, it does not do x= 10. It does 0-9. Equal is not less than, so the condition fails.






Last edited on
Topic archived. No new replies allowed.