Mathemathic...

1. tt
Member
Join Date
Dec 1969
Posts
46

## Mathemathic...

Hi!<BR><BR>I feel wery stupid now but it must be the vacation that is responsible ;-)<BR>Anyway my brain doesn´t work today and i´m stucked with this simple function..<BR><BR>I want to call a function with a number and get in return faculty(?) i.e call function integerReturn(3) and that function will process it like this:<BR>3*2*1=6 (returns 6)<BR>And if I feed it with integerReturn(5) it will process it like this:<BR>5*4*3*2*1=120 (returns 120)<BR><BR>It can be a number of whatever that i&#039;m gonna feed it with!<BR><BR>Sorry for a stupid question but sometimes the brain doesn´t work as it should ;-(<BR><BR>Best // TT

2. Senior Member
Join Date
Dec 1969
Posts
787

## RE: Mathemathic...

function returnfactorial(num)<BR>dim counter, total<BR>total = 1<BR>for counter=num to 1<BR>total = total * counter<BR>next<BR>return total<BR>end function

3. Senior Member
Join Date
Dec 1969
Posts
5,955

## I don't think there is one in VBScript...

...(nor JScript for that matter) so you&#039;ll have to program your own.<BR><BR>Oliver.

4. tt
Member
Join Date
Dec 1969
Posts
46

## RE: I don't think there is one in VBScript...

Wow... VB is dead... Do You really mean that ;-)

5. tt
Member
Join Date
Dec 1969
Posts
46

## RE: Mathemathic... Great solution! :-)

Thanks!<BR>In VB It will look like this..<BR>Had to add something... (step -1)<BR><BR>Function returnfactorial(num As Integer)<BR>Dim counter, total<BR>total = 1<BR>For counter = num To 1 Step -1<BR>total = total * counter<BR>Next<BR>returnfactorial = total<BR>End Function

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## Nice way to get your homework done...

...but I&#039;ll bet that the instructor asked you to do this using recursion. Which that solution does not use.<BR><BR>

7. Senior Member
Join Date
Dec 1969
Posts
136

## RE: Nice way to get your homework done...

ahhh recursion, the scourge of c.s.1

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## LOL! True...

...but when you need recursion, you need it.<BR><BR>Like this answer:<BR>http://www.aspmessageboard.com/forum/advanced.asp?M=712965&T=712786&F=27&P=1<BR>(and the one right after it, same thread).<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•