Qbasicnews.com
January 21, 2022, 11:58:37 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Triangular Number Function  (Read 1719 times)
Arctic
New Member

Posts: 9


WWW
« on: July 29, 2003, 02:10:52 PM »

This is just a small function to return the nth triangular number... I can't think of an application at this time, I was just bored in math class. Smiley

The first code has to do with summation notation (sigma for you math gurus)

Code:
FUNCTION NTriNum& (n&)
  FOR x = 1 TO n&
    result& = result& + x
  NEXT x
  NTriNum& = result&
END FUNCTION


OR:

The second code is simply the fomula derived from the summation...

Code:
Function NTriNum&(n&)
  NTriNum& = ((n&^2) + n&) \ 2
END FUNCTION


Note: I tested them with longs so I could see the 10,000th triangular number, which was 50,005,000 just in case anyone was wondering Smiley
Logged
oracle
*/-\*
*****
Posts: 3652



WWW
« Reply #1 on: July 30, 2003, 03:10:39 AM »

Wait until StatLib comes out, you'll be able to do the 1,000,000,000,000,000,000,000,000,000,000,000,000,000....th triangle number with ease...
Logged

Flexibal
Forum Regular
**
Posts: 128



WWW
« Reply #2 on: July 30, 2003, 09:50:28 AM »

are you using strings to represent numbers? or BCD? or what?



[Flexibal>
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!