COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.
WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
0 TO 20?
OK, done.
Now, did you have a question about C?
<off-topic>
For what it's worth, you have apparently asked us to do your homework for
you. You were given this homework to help you understand the use of and
practice certain methods and facilities, and if we do your homework for
you, it defeats the purpose of the homework.
We are not a "homework help line", but if you post what you've done so far,
we can help you by making suggestions as to how to fix what you've done.
/I/ will go further than that, though. I will tell you how to write the
program you've asked us about.
First off, don't even think of C.
Get a sheet of paper, and write down all the even numbers between 0 and 20.
Add them up, and write down the total.
Study this for a moment, remembering exactly how you worked out the
solution. How did you pick "even numbers"? How did you know where to start?
How did you know where to stop?
Now, on another sheet of paper, write down the steps that you took. Start
with how you decided where to start. Include how you decided to pick even
numbers, how you added the numbers together, and end with how you decided
to stop.
Once you can /clearly/ explain how to solve the problem /on paper/, you can
then look for programming language tools that you can use to follow that
explanation. Use these tools, and write a short C program that does what
you did manually. Then try it, and see if it gets the same answer you got
when you did it manually. If it doesn't work, show us what you did, and we
can help get you back on track.
A suggestion/hint for this stage: the C "for()" construct has four parts:
1) a part that tells it where to start,
2) a part that tells it how much to change by,
3) a part that tells it where to stop, and
4) a part that tells it what to do at each step.
That sounds a lot like the things I asked you to remember from before,
doesn't it?
</off-topic>
--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------