you are asked to make a program that would ask for 2 numbers. you are to print all even numbers from the 1st number, up to the 2nd. for example . 1 and 10 , then print 2, 4, 6, 8, 10. then the program stops. whats the source code?
please and thank you :))
Three answers:
J.J.'s Advice / Avis de J.J.
2009-10-05 20:09:56 UTC
Giving you the actual code would be cheating.
But think about this: Let's call the 1st number "num1" and the 2nd number "num2".
- If num1 is even, print num1.
- Else, num1=num1+1, and print num1
- If num1+2<=num2, print num1+2
- num1=num1+2
and so on...
- if num1+2 is not lesser than or equal to num2 and if num2 is even) then print num2 and end program.
- Else (if num2 is odd) then end program.
i.e. 2 and 10. If 2 is even (it is). then 2 will be printed. If 2+2 is lesser than or equal to 10 (it is) then 4 will be printed. 2 is then replaced with 4. If 4+2 is lesser than or equal to 10 (it is), then 6 will be printed.
The trick here will be telling it how to determine whether or not a number is even or odd ;)
Mani S
2009-10-06 03:02:00 UTC
Here's the code -http://paste.uni.cc/20258
Hope this helps :)
anonymous
2016-05-21 07:18:59 UTC
you should take averageage as float
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.