Single Post

Header

Sunday, September 30, 2012

vb script programs

1.Find the factorial of a number using vb script

' vb script program to find the factrial of a given number

n=cint(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

2.Find the fibonacci series of a number using vb script

' fibonacci series of a given number
n=cint(inputbox("enter a number"))
dim f0,f1,f2
f0=0
f1=1
f2=f0+f1

var="The fibonacci series of a given number "&n&" is :"&vbnewline

var=var&" "&f0&" "&f1
do while(f2<=n)
var=var&" "&f2
f0=f1
f1=f2
f2=f0+f1
loop
msgbox var

3.Search whether the given name is exists or not using vb script

' vb script prgram to give some names in the array and search for the given name
' whether the given name is exists or not

names=array("gopi","ramu","ravi","raju")

str=inputbox("enter name to search")
for i=0 to ubound(names)
if str=names(i) then
msgbox "the given name "&str&" is there "
exit for
end if
next

if i=ubound(names)+1 then
msgbox "the given name "&str&"is not there"
end if


4.Find the sum of diagonal elements in the matrix using vb script

'vb script program to find sum of diagonal elements in the given matrix
' declare double dimentional array
dim a(2,2)
dim sum,k
sum=0
k=0
for i=0 to ubound(a,1)
for j=0 to ubound(a,2)
a(i,j)=cint(inputbox("enter elements"))
next
sum=sum+a(i,k)
k=k+1
next
msgbox sum

5.Display row and column elements in the array using vb script

'vb script program to display row and column elements in the given matrix
' declare double dimentional array in vb script
dim a(1,2)
dim row,col

col=""
for i=0 to ubound(a,1)
row=""
for j=0 to ubound(a,2)
a(i,j)=cint(inputbox("enter elements"))
row=row&" "&a(i,j)
next
msgbox row
next

for i=0 to ubound(a,2)
col=""
for j=0 to ubound(a,1)
'a(i,j)=cint(inputbox("enter elements"))
col=col&" "&a(j,i)
next
msgbox col
next

6.Tracebility of a given matrix using vb script

'vb script program to tracebility of the given matrix
' declare double dimentional array in vb script
dim a(1,1),b(1,1)
dim row,col

for i=0 to ubound(a,1)
for j=0 to ubound(a,2)
a(i,j)=cint(inputbox("enter elements"))
next
next

for i=0 to ubound(a,2)
for j=0 to ubound(a,1)
b(i,j)=a(j,i)
msgbox b(i,j)
next
next

No comments:

Post a Comment