Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 02-11-2010, 10:39 PM   #1
LQ Newbie
Registered: Jul 2009
Posts: 3

Rep: Reputation: 0
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.
Old 02-12-2010, 12:11 AM   #2
Senior Member
Registered: Jul 2005
Distribution: Slackware
Posts: 2,014

Rep: Reputation: 115Reputation: 115
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):
Old 02-12-2010, 02:17 PM   #3
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
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.
 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.
Old 02-18-2010, 09:52 AM   #4
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
sum of output phsythax Linux - Newbie 12 12-16-2009 07:36 PM
MD5 sum Pedroski Linux - Software 4 12-08-2009 03:17 PM
sequence of numbers, how to extract which numbers are missing jonlake Programming 13 06-26-2006 04:28 AM
Adding numbers, break on non-numbers... Cruger Programming 1 03-22-2004 10:18 AM
Check sum emmanuelmathew Linux - Newbie 2 02-12-2003 02:14 AM > Forums > Non-*NIX Forums > Programming

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration