VBScript Programs PART - I
'****************************************************
'1 Print Hello World
Print "Hello World"
'****************************************************
'2 Find whether given number is an odd number
Dim oNum
oNum=4
If oNum mod 2 <>0 Then
Print "The Number "& oNum &" is an Odd Number"
else
Print "The Number "& oNum &" is not an Odd Number"
End If
'****************************************************
'3 Print odd numbers between given range of numbers
Dim RangeStart
Dim RangeEnd
Dim iLoop
RangeStart=10
RangeEnd=20
For iLoop=RangeStart to RangeEnd
If iLoop mod 2 <>0 Then
Print oNum
End If
Next
'****************************************************
'4 Find the factorial of a given number
Dim oNum
Dim iLoop
Dim fnValue
oNum=6
fnValue=1
For iLoop=oNum to 1 step-1
fnValue=fnValue*iLoop
Next
print fnValue
'****************************************************
'5 Find the factors of a given number
Dim oNum
Dim iLoop
oNum=10
For iLoop=1 to oNum/2
If oNum mod iLoop=0 Then
print iLoop
End If
Next
print oNum
'****************************************************
'6 Print prime numbers between given range of numbers
Dim RangeStart
Dim RangeEnd
Dim iLoop
RangeStart=1
RangeEnd=30
For iLoop=RangeStart to RangeEnd
For iCount=2 to round(iLoop/2)
If iLoop mod iCount=0 Then
Exit for
End If
Next
If iCount=round(iLoop/2)+1 or iLoop=1 Then
print iLoop
End If
Next
'****************************************************
'7 Swap 2 numbers without a temporary variable
Dim oNum1
Dim oNum2
oNum1=1055
oNum2=155
oNum1=oNum1-oNum2
oNum2=oNum1+oNum2
oNum1=oNum2-oNum1
print oNum1
print oNum2
'****************************************************
'8 write a program to Perform specified Arithmetic Operation on two given numbers
Dim oNum1
Dim oNum2
Dim oValue
oNum1=10
oNum2=20
OperationtoPerform="div"
Select Case lcase(OperationtoPerform)
Case "add"
oValue=oNum1+oNum2
Case "sub"
oValue=oNum1-oNum2
Case "mul"
oValue=oNum1*oNum2
Case "div"
oValue=oNum1/ oNum2
End Select
print oValue
'****************************************************
'9 Find the length of a given string
Dim oStr
Dim oLength
oStr="sudhakar"
oLength=len(oStr)
print oLength
'****************************************************
'10 Reverse given string
Dim oStr
Dim oLength
Dim oChar
Dim iLoop
oStr="sudhakar"
oLength=len(oStr)
For iLoop=oLength to 1 step-1
oChar=oChar&mid(oStr,iLoop,1)
Next
print oChar
'****************************************************
No comments:
Post a Comment