I need help !!!VB08 question

Started by junhang lee, May 19, 2010, 06:33 AM

Previous topic - Next topic

junhang lee

Factorial calculation
...
5! = 5*4*3*2*1
4! = 4*3*2*1
...
X! = x*(x-1)*(x-2)*....*1
(x-1)!= (x-1)*(x-2)*....*1

can anyone tell me how to do this ? thank you very much!

VelMurugan

Hi,

Dim x,sum,i,j as integer
x=5
sum=1
for (j=x; j>=1; j--)
{
for (i=j; i>=1; i--)
{
sum=sum * i;
}
}

Output : 34560

(5*4*3*2*1) * (4*3*2*1) * (3*2*1) * (2*1) * 1



if you want only 5! means


Dim x,sum,i as integer
x=5
sum=1
for (i=x; i>=1; i--)
{
sum=sum * i;
}


Output : 120

(5*4*3*2*1)