write a vb script to calculate factorial of a number?

Answers were Sorted based on User's Feedback



write a vb script to calculate factorial of a number?..

Answer / mudaseer

vf=1
vnum=inputbox("enter a no")
for i=2 to vnum
vf=vf*i
next
msgbox vf

Is This Answer Correct ?    98 Yes 25 No

write a vb script to calculate factorial of a number?..

Answer / raja

Dim n,f
n=inputbox("enter a number")
f=1
If n<0 Then
msgbox "invalid number"
else if n=0 or n=1 then
msgbox "the factorial of given number is : "& f
else
For i=1 to n
f=f*i
Next
msgbox "the factorial of given number is : "&f
End If
end if

Is This Answer Correct ?    77 Yes 19 No

write a vb script to calculate factorial of a number?..

Answer / rik mondal

The answer submitted by "mudaseer" is absolutely wrong and
the answer by "raja" is partially correct(because he did not
wrote additional HTML and script tags,which is difficult to
understand for beginners). Guys don't you check the answer
before posting?
anyways here is the correct answer. This will work 100%.
Just copy it and paste in you editor then save and compile
by IE.


<html>
<script language="vbscript">
n=inputbox("Enter a number")
dim f
f=1
if n<0 then
Msgbox "Invalid number"
elseif n=0 or n=1 then
MsgBox "The factorial of given number "&n&" is :"&f
else
for i=n to 2 step -1
f=f*i
next
MsgBox "The factorial of given number "&n&" is :"&f
end if
</script>
</html>

Is This Answer Correct ?    41 Yes 16 No

write a vb script to calculate factorial of a number?..

Answer / arvind singh

a = InputBox("Enter a no to calculate factorial for")
Result = 1
Do While a > 0
Result = Result*(a)
a = a-1
Loop
MsgBox Result

Is This Answer Correct ?    8 Yes 4 No

write a vb script to calculate factorial of a number?..

Answer / mogal

n = 12345
f =1
for i =1 to len(n)
f = f* i
next
msgbox f

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More VB Script Interview Questions

Hi everybady, i have faced few Qns in one of i attended interview, please help me out with these below Qns. 1. how to join values without using join function? 2. how to compare values without using String compare function? 3. input is Bangalore, but i need output like this below format, what is function to use and get this outcome B A N G A L o R E 4. Input is "CapGemini" but uotput should be like this "inimeGpaC" 5. Input is 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Can someone let me know results of this Qns, please. Thanks.

2 Answers   CSS Corp,


input values to accept 2 numbers & print the product, difference and sum using switch case

1 Answers   CSC,


How to open browser in vb script?

0 Answers  


Explain about .wsf files?

0 Answers  


What is the use of "Option Explicit"?

2 Answers  






i want to when we will write the scripts either after getting the build or after getting the SRS?

3 Answers  


Hellow friends, I am learning QTP,but here problem is VB script. please guide me how to learn VB script w.r.t QTP and if you know any books tell me or if you have any materials or any use full material or any else w.r.t QTP please post me p.p.sekhar

0 Answers  


Explain the filter expression?

0 Answers  


How to pass argument by reference to a function in vbscript?

0 Answers  


write a vb script code to display the vbscript word by word (i e 1st it should display v then b and up to t )

1 Answers  


how to find greatest of n numbers!

3 Answers   Syscon,


Explain a few date functions in vbscript

0 Answers  


Categories