You are on page 1of 9

1.

JavaScript program to find the greatest common divisor (gcd) of two positive
numbers

var gcd = function(a, b) {

if ( ! b) {

return a;

return gcd(b, a % b);

};

console.log(gcd(2154, 458));

output=2

2. JavaScript program to get the integers in range (x, y).

var range = function(start_num, end_num)

if (end_num - start_num === 2)

return [start_num + 1];

else

var list = range(start_num, end_num - 1);

list.push(end_num - 1);

return list;

};

console.log(range(2,9));

out put =[3,4,5,6,7,8]


3. JavaScript program to compute the sum of an array of integers

var array_sum = function(my_array) {

if (my_array.length === 1) {

return my_array[0];

else {

return my_array.pop() + array_sum(my_array);

};

console.log(array_sum([1,2,3,4,5,6]));

output=21

4. JavaScript program to compute the exponent of a number

var exponent = function(a, n)

if (n === 0)

return 1;

else

return a * exponent(a, n-1);

};

console.log(exponent(4, 2));

output=16
5. JavaScript program to get the first n Fibonacci numbers.

var fibonacci_series = function (n)

if (n===1)

return [0, 1];

else

var s = fibonacci_series(n - 1);

s.push(s[s.length - 1] + s[s.length - 2]);

return s;

};

console.log(fibonacci_series(8));

output=[0.1.1.2.3.5,8,13,21]

6. JavaScript program to check whether a number is even or not

function is_even_recursion(number)

if (number < 0)

number = Math.abs(number);

if (number===0)

{
return true;

if (number===1)

return false;

else

number = number - 2;

return is_even_recursion(number);

console.log(is_even_recursion(234)); //true

console.log(is_even_recursion(-45)); // false

console.log(is_even_recursion(-45)); // false

output=true

false

false

7. JavaScript program for binary search

Array.prototype.br_search = function (target)

var half = parseInt(this.length / 2);

if (target === this[half])

return half;

if (target > this[half])

{
return half + this.slice(half,this.length).br_search(target);

else

return this.slice(0, half).br_search(target);

};

l= [0,1,2,3,4,5,6];

console.log(l.br_search(5));

output=5
1.W.A.P to calculate the expression a = 5-2*2/5^3 in vb script
<html>
<head>

<script type="text/vbscript">

Dim a
a = 5-2*2/5^3
document.write(a)
</script>

</head>
<body>

</body>
</html>

2.W.A.P. to find the age between 18-70 in vb script

<html>
<head>
<script type="text/vbscript">
Dim age
age = InputBox("Enter your age")
If age<18 Then
document.write("You are too young.")
ElseIf age<45 Then
document.write("You are still young.")
ElseIf age<70 Then
document.write("You are getting older.")
Else
document.write("You are too old.")
End If

</script>

</head>
<body>
</body>
</html>
3.vbscript to find the vowel in a word

<html>
<head>

<script type="text/vbscript">
Dim name, length
name = InputBox("Enter your name")
length = Len(name)’Gives length of the input string

For i = 1 To length
txt = Mid(name,i,1)'Returns a specified number of characters from a string, the
first parameter is the string, second parameter is the starting position and third
parameter is the number of characters to return
If txt="a" or txt="A" or txt="e" or txt="E" or txt="i" or txt="I" or txt="o" or
txt="O" or txt="u" or txt="U" Then
counter = counter+1
End If
Next
document.write("Hi " & name & "!!!Your name contains " & counter & " vowels.")
</script>

</head>
<body>

</body>
</html

4.vb script to find the result

<script type="text/vbscript">
Function returnResult(ByRef value)
value = value +1
returnResult = value
End Function
Dim x
x=5
call returnResult(x)
document.write(x)
</script>

5. vb script to print number between 0-5


For i=5 To 0 step -1
WScript.Echo i
Next
4. vbscript to find marks in the subject

<html>
<body>
<script type="text/vbscript">
Option Explicit
‘Dim markE, markM, markT
markE=90
markM=86
markT=markE+markM
document.write("Your marks in English is " & markE & "." & "<br />")
document.write("Your marks in Mathematics is " & markM & "." & "<br />")
document.write("Your total marks is " & markT & ".")
</script>

</body>
</html>

5. vbscript to get marks with student name and id number

<html>
<body>

<script type="text/vbscript">
Option Explicit
Dim students(19), marks(19)
students(0) = "John"
marks(0) = 95
students(1) = "Emma"
marks(1) = "83"
students(2) = "Kevin"
marks(2) = 87

document.write(students(0) & " has scored " & marks(0) & ".<br />")
document.write(students(1) & " has scored " & marks(1) & ".<br />")
document.write(students(2) & " has scored " & marks(2) & ".<br />")
</script>

</body>
</html>
6. program to find the area

<html>
<head>

<script type="text/vbscript">
Dim intRadius
intRadius = 20
const pi=3.14
area = pi*intRadius^2
document.write(area)
</script>

</head>
<body>
</body>
</html>

You might also like