write a vb script to calculate factorial of a number?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
Create a file system object to do the following i. Create a folder ii. Create a text file in the folder iii. Update text file with some tex
what is resorceallocation
Why is the use of exit do or exit for statements within loops discouraged?
Can anybody code this problem for me in VB script - Create an array of 4 elements, increase its size to 7 elements and then find out which of the elements are prime (use functions)
How are values assigned to the variables in the vbscript language?
write a vb script create 5 folders test1 test2 test3 test4 test5
Is VB Script Case sensitive or Case insensitive?
How to write VB script for login module?
How to Import data from a file (file is on the desktop) to the data table
What is the use of option explicit statement?
What is byref and byval parameters in vbscript?
in qtp we ve datatable look like excel ,if we want to extract data from excel which saved in my documet how can i get that in datatable using vb script