Wednesday, 16 March 2011

Code 1: Technique to add first ten natural numbers

Problem Description:
First 10 natural numbers inc
lude 1,2,3,....,10. We have to add them all. Here we need a technique by which we can get all the natural numbers. one at a time so that we can add each one of them. This can be done by using for loop are while in C or C++. As far as other languages are concerned you need to find a suitable syntax for applying the above technique. Next we need to think about adding them. Now to add them we require simple math, sum=sum+i, called Summation technique, where initially sum=0 (as it may contain garbage value which may add up giving incorrect result)
Now each time you have to change the value of i in such a way that you get the values starting from 1 and incrementing up to 10.



For more visit www.TechnoCode.co.in

No comments:

Post a Comment