Factorial of large number in ruby(programming language)....
#Author"shivamzaz"@imsec(2cs)(2ndyr)
#Based on simple maths concept(carry based)
#Large value factorial in ruby...
#Session"2015"
def factorial(n);
a=[] #intialize array
a[0]=1 #let fist value of array is 1 as usual like factorial simple defn concept
a_size=1
for x in 2..n;
a_size=mult(x,a,a_size) #function call
end
g=a.size-1 #display the result in reverse wise.....due to carry maintenance
while(g>=0);
print a[g]
g-=1
end
end
def mult(x,a,a_size);
cry=0
for i in 0..a_size-1;
pro=x*a[i]+cry
cry=pro/10
a[i]=pro%10
end
while(cry>0);
a[a_size]=cry%10
cry=cry/10
a_size+=1
end
return a_size
end
factorial(gets().to_i) #fucnction call
---------------------------------------------------------------------------------------------------------------------------------------------
that's all...
<<<<<<<Happy Coding>>>>>.
#Author"shivamzaz"@imsec(2cs)(2ndyr)
#Based on simple maths concept(carry based)
#Large value factorial in ruby...
#Session"2015"
def factorial(n);
a=[] #intialize array
a[0]=1 #let fist value of array is 1 as usual like factorial simple defn concept
a_size=1
for x in 2..n;
a_size=mult(x,a,a_size) #function call
end
g=a.size-1 #display the result in reverse wise.....due to carry maintenance
while(g>=0);
print a[g]
g-=1
end
end
def mult(x,a,a_size);
cry=0
for i in 0..a_size-1;
pro=x*a[i]+cry
cry=pro/10
a[i]=pro%10
end
while(cry>0);
a[a_size]=cry%10
cry=cry/10
a_size+=1
end
return a_size
end
factorial(gets().to_i) #fucnction call
---------------------------------------------------------------------------------------------------------------------------------------------
that's all...
<<<<<<<Happy Coding>>>>>.