LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 02-11-2010, 09:39 PM   #1
palpankaj
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 09:41 PM.
 
Old 02-11-2010, 11:11 PM   #2
tuxdev
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):
http://mywiki.wooledge.org/BashGuide...til_and_for.29
http://mywiki.wooledge.org/ArithmeticExpression
 
Old 02-12-2010, 01:17 PM   #3
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

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

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


Reply


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 06:36 PM
MD5 sum Pedroski Linux - Software 4 12-08-2009 02:17 PM
sequence of numbers, how to extract which numbers are missing jonlake Programming 13 06-26-2006 03:28 AM
Adding numbers, break on non-numbers... Cruger Programming 1 03-22-2004 09:18 AM
Check sum emmanuelmathew Linux - Newbie 2 02-12-2003 01:14 AM


All times are GMT -5. The time now is 01:31 AM.

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