Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org sum the numbers between and including a and b
 Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.

Notices

 02-11-2010, 10:39 PM #1 palpankaj LQ Newbie   Registered: Jul 2009 Posts: 3 Rep: sum the numbers between and including a and b Please help me to write a script in bash or shell to add the numbers between and including two numbers Thanks in Advance Last edited by palpankaj; 02-11-2010 at 10:41 PM.
 02-12-2010, 12:11 AM #2 tuxdev Senior Member   Registered: Jul 2005 Distribution: Slackware Posts: 2,014 Rep: We aren't going to do your homework, but here's some good reading material (and throw away whatever it is you're reading now): http://mywiki.wooledge.org/BashGuide...til_and_for.29 http://mywiki.wooledge.org/ArithmeticExpression
 02-12-2010, 02:17 PM #3 jschiwal LQ Guru   Registered: Aug 2001 Location: Fargo, ND Distribution: SuSE AMD64 Posts: 15,733 Rep: Actually, this problem reminds me of when I derived the formula on my own in high school. Before there was such a thing as home computers. Sometimes the way you look at the problem is what provides the solution. Code: ``` 0 1 2 3 4 5 6 7 15 14 13 12 11 10 9 8``` Maybe a better hint is that since the average = total / items, it follows that the total is the average * items. That should help you derive the formula. You can either derive it directly or subtract the formula for a 1-m series from a 1-n series and reduce the formula for the formula of the sum of a m-n series. Last edited by jschiwal; 02-13-2010 at 11:35 AM.
 02-18-2010, 09:52 AM #4 pixellany LQ Veteran   Registered: Nov 2005 Location: Annapolis, MD Distribution: Arch/XFCE Posts: 17,802 Rep: Per the LQ Rules, please do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and Google searches) and we'll do our best to help. Also, keep in mind that your instructor might also be an LQ member.

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post phsythax Linux - Newbie 12 12-16-2009 07:36 PM Pedroski Linux - Software 4 12-08-2009 03:17 PM jonlake Programming 13 06-26-2006 04:28 AM Cruger Programming 1 03-22-2004 10:18 AM emmanuelmathew Linux - Newbie 2 02-12-2003 02:14 AM

LinuxQuestions.org

All times are GMT -5. The time now is 12:35 AM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -