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

When does ‘on click of button’ event gets triggered in the vbscript language?

0 Answers  


how to set one column as primary key in QTP and fetch values accordingly

0 Answers   Ford,


Write a program to resize an array of 5 elements to 4 elements and display all the elements.

1 Answers  


write generic functions for webapplication?like generic function for webedit generic function for webbutton generic function for links

1 Answers  


Hi I don't have any idea on VBscript. can any one point me to a good web site to learn VBscript. Regards lina

2 Answers  






How to find arry size in qtp vb script

2 Answers   Cap Gemini,


How to make professional test report using vbscript code in UFT, which gives us complete analysis of the test.

0 Answers   College School Exams Tests,


Mention what is byref and byval parameters in vbscript?

0 Answers  


Mention what is the difference between vbscript and vba?

0 Answers  


How to find the font in qtp. Scenario:After entering the username and passwd you will be navigate into the "welcome:Username" page.Now I want to extarct font for this message.

0 Answers   GE, iGate,


What is the event handling in vbscript?

0 Answers  


Which operator can be used to check if two numbers are equal or not in vbscript?

0 Answers  


Categories