07-29-2003, 10:10 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.
The first code has to do with summation notation (sigma for you math gurus)
OR:
The second code is simply the fomula derived from the summation...
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
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