© atish shrestha · 2020. 9. 14. · 2. WAP to convert the distance in kilometer to mile by using...
Transcript of © atish shrestha · 2020. 9. 14. · 2. WAP to convert the distance in kilometer to mile by using...
© atish shrestha
1. WAP to input any two numbers and display their sum
using SUB…END SUB.
DECLARE SUB sum (a,b)
CLS
INPUT “Enter any two numbers”;a,b
CALL sum (a,b)
END
SUB sum (a,b)
s = a + b
PRINT “the sum is ”;s
END SUB
© atish shrestha
2. WAP to convert the distance in kilometer to mile by
using SUB….END SUB.
DECLARE SUB convt (km)
CLS
INPUT “Enter distance in kilometers”; km
CALL convt (km)
END
SUB convt (km)
mile = km / 1.6
PRINT “the distance in mile= ”; mile
END SUB
© atish shrestha
3. WAP to input length and breadth and calculate the
area of a rectangle using SUB….END SUB.
DECLARE SUB area (l, b)
CLS
INPUT “Enter length”; l
INPUT “Enter breadth”; b
CALL area (l, b)
END
SUB area (l, b)
a = l * b
PRINT “the area= ”; a
END SUB
© atish shrestha
4. WAP to input temperature in centigrade and convert it
into Fahrenheit using SUB….END SUB.
DECLARE SUB temp (c)
CLS
INPUT “Enter the temperature in centigrade”; c
CALL temp (c)
END
SUB temp (c)
f = 9/5 * c + 32
PRINT “the temperature in Fahrenheit= ”; f
END SUB
© atish shrestha
5. WAP to input length, breadth and height and calculate
the area and volume and display them using
SUB….END SUB.
DECLARE SUB area (l, b)
DECLARE SUB vol (l, b, h)
CLS
INPUT “Enter length, breadth, height”; l, b, h
CALL area (l, b)
CALL vol (l, b, h)
END
SUB area (l, b) SUB vol (l, b, h)
a = l * b v = l * b * h
PRINT “the area= ”; a PRINT “the volume= ”;v
END SUB END SUB
© atish shrestha
6. WAP to input any three numbers and display the greatest
number using SUB…..END SUB.
DECLARE SUB great (a, b, c)
CLS
INPUT “Enter any three numbers”; a, b, c
CALL great (a, b, c)
END
SUB great (a, b, c)
IF a>b AND a>c THEN g = a
IF b>a AND b>c THEN g = b
IF c>a AND c>b THEN g = c
PRINT “the greatest number= ” ; g
END SUB
© atish shrestha
7. WAP to input any three numbers and display the greatest
and smallest numbers using SUB…..END SUB.
Main Module
DECLARE SUB great (a, b, c)
DECLARE SUB small (a, b, c)
CLS
INPUT “Enter first number”; a
INPUT “Enter second number”; b
INPUT “Enter third number”; c
CALL great (a, b, c)
CALL small (a, b, c)
END
© atish shrestha
SUB Module 1
SUB great (a, b, c)
IF a>b AND a>c THEN g = a
IF b>a AND b>c THEN g = b
IF c>a AND c>b THEN g = c
PRINT “the greatest number= ” ; g
END SUB
SUB Module 2
SUB small (a, b, c)
IF a<b AND a<c THEN s = a
IF b<a AND b<c THEN s = b
IF c<a AND c<b THEN s = c
PRINT “the smallest number= ” ; s
END SUB © atish shrestha
8. WAP to input any number and display whether the
entered number is even or odd using SUB….END SUB.
DECLARE SUB oddeven (n)
CLS
INPUT “Enter any number”; n
CALL oddeven (n)
END
SUB oddeven (n)
IF n MOD 2 = 0 THEN
PRINT n; “is an even number”
ELSE
PRINT n; “is an odd number”
END IF
END SUB
© atish shrestha
9. WAP to display the natural numbers from 1 to 10 using
SUB….END SUB.
DECLARE SUB ser ( )
CLS
CALL ser
END
SUB ser
FOR i = 1 to 10 TO 10
PRINT ii;
NEXT
END SUB
© atish shrestha
10. WAP to display even numbers from 2 to 20 and their sum
SUB….END SUB.
DECLARE SUB ser ( )
CLS
CALL ser
END
SUB ser
FOR i = 2 TO 20 STEP 2
PRINT i;
s = s + i
NEXT
PRINT “the sum of even numbers= ”; s
END SUB
© atish shrestha
11. WAP to display the series 5 55 555 5555 55555
using SUB….END SUB.
DECLARE SUB ser ( )
CLS
CALL ser
END
SUB ser
a = 5
FOR i = 1 TO 5
PRINT a;
a = a * 10 + 5
NEXT i
END SUB
© atish shrestha
12. WAP to display the series 55555 5555 555 55 5
using SUB….END SUB.
DECLARE SUB ser ( )
CLS
CALL ser
END
SUB ser
a = 55555
FOR i = 1 TO 5
PRINT a;
a = a \ 10
NEXT i
END SUB
© atish shrestha
13. WAP to display the following output using SUB….END
SUB.
1
1 1
1 1 2
1 1 2 3
DECLARE SUB patt ( )
CLS
CALL patt
END
SUB patt
a = 1
FOR i = 1 TO 4
PRINT a;
a = a * 10 + i
NEXT i
END SUB
© atish shrestha
14. WAP to display the series 1 8 27….. upto 10th term
using SUB….END SUB.
DECLARE SUB ser ( )
CLS
CALL ser
END
SUB ser
FOR i = 1 TO 10
PRINT i ^ 3 ;
NEXT i
END SUB
© atish shrestha
15. WAP to display Fibonacci series 1 1 2 3 5
8 13 21 34 55 using SUB….END SUB.
DECLARE SUB fibo ( )
CLS
CALL fibo
END
SUB fibo
a = 1
b = 1
FOR i = 1 TO 10
PRINT a;
c = a + b
a = b
b = c
NEXT i
END SUB
© atish shrestha
16. WAP to display the following series using SUB….END SUB.
2 8 18 32 ………up to 10th term
DECLARE SUB ser ( )
CLS
CALL ser
END
SUB ser
FOR i = 1 TO 10
PRINT 2 * i ^ 2;
NEXT i
END SUB
© atish shrestha
17. WAP to display the following pattern using SUB….END
SUB.
N
N E
N E P
N E P A
N E P A L
DECLARE SUB patt ( )
CLS
CALL patt
END
SUB patt
a$ = “NEPAL”
FOR i = 1 TO LEN (a$)
PRINT LEFT$ (a$, i)
NEXT i
END SUB
© atish shrestha
18. WAP to display the following pattern using SUB….END
SUB.
N E P A L
N E P A
N E P
N E
N
DECLARE SUB patt ( )
CLS
CALL patt
END
SUB patt
a$ = “NEPAL”
FOR i = LEN (a$) TO 1 STEP -1
PRINT LEFT$ (a$, i)
NEXT i
END SUB
© atish shrestha
19. WAP to input any string from the user and display it in
reverse order using SUB….END SUB.
DECLARE SUB rev (w$)
CLS
INPUT “enter any string”; w$
CALL rev (w$)
END
SUB rev (w$)
FOR x = LEN (w$) TO 1 STEP -1
r$ = r$ + MID$ (w$, x, 1)
NEXT x
PRINT “the reverse string is ”; r$
END SUB
© atish shrestha
20. WAP to input any string from the user and display whether
the string is palindrome or not using SUB….END SUB.
DECLARE SUB palin (w$)
CLS
INPUT “enter any string”; w$
CALL palin (w$)
END
SUB palin (w$)
FOR x = LEN (w$) TO 1 STEP -1
r$ = r$ + MID$ (w$, x, 1)
NEXT x
IF w$ = r$ THEN
PRINT “the string is palindrome”
ELSE
PRINT “the string is not palindrome”
END IF
END SUB
© atish shrestha
21. WAP to input any string and display the number of vowels in
the string using SUB….END SUB.
DECLARE SUB vowel (s$)
CLS
INPUT “enter any string”; s$
CALL vowel (s$)
END
SUB vowel (s$)
FOR x = 1 TO LEN (s$)
a$ = MID$ (s$, x, 1)
SELECT CASE UCASE$(a$)
CASE “A”, “E”, “I”, “O”, “U”
c = c + 1
END SELECT
NEXT x
PRINT “The number of vowels= ”;c
END SUB
© atish shrestha
22. WAP to input any string and display the number of words in
the string using SUB….END SUB.
DECLARE SUB count (s$)
CLS
INPUT “enter any sentence”; s$
CALL count (s$)
END
SUB count (s$)
c = 1
FOR i = 1 TO LEN (s$)
a$ = MID$ (s$, i, 1)
IF a$ = “ ” THEN c = c + 1
NEXT i
PRINT “The number of words= ”;c
END SUB
© atish shrestha
23. WAP to display the series 5 6 9 14 21 30
using SUB….END SUB.
DECLARE SUB ser ( )
CLS
CALL ser
END
SUB ser
a = 5
n = 1
WHILE a < = 30
PRINT a;
a = a + n
n = n + 2
END SUB
© atish shrestha
24. WAP to display the following series using SUB….END SUB.
.1 .11 .111 .1111 .11111
DECLARE SUB ser ( )
CLS
CALL ser
END
SUB ser
a = 0
FOR i = 1 TO 5
a = a + 0.1 ^ i
PRINT a;
NEXT i
END SUB
© atish shrestha
25. WAP to display the following series using SUB….END SUB.
8 18 32 50 72 98….. up to 10th term
DECLARE SUB ser ( )
CLS
CALL ser
END
SUB ser
a = 2
n = 1
WHILE n<=10
PRINT 2 * a ^ 2;
a = a + 1
n = n + 1
WEND
END SUB
© atish shrestha
26. WAP to display the following series using SUB….END SUB.
3 12 27…….. up to 10th term
DECLARE SUB ser ( )
CLS
CALL ser
END
SUB ser
FOR n = 1 TO 10
PRINT 3 * n ^ 2;
NEXT n
END SUB
© atish shrestha
27. WAP to display the multiplication table of 5 using
SUB….END SUB.
DECLARE SUB mul (n)
CLS
CALL mul (5)
END
SUB mul (n)
FOR I = 1 TO 10
PRINT n; “X”; I; “=”; n * I
NEXT I
END SUB
© atish shrestha
28. WAP to display the multiplication table from 2 to 9 using
SUB….END SUB.
DECLARE SUB table ( )
CLS
CALL table
END
SUB table
FOR x = 2 TO 9
FOR y = 1 TO 10
PRINT x; “X”; y; “=”; x*y
NEXT y
NEXT x
END SUB
© atish shrestha
29. WAP to input a number and display whether the number
is perfect square or not using SUB….END SUB.
DECLARE SUB square (n)
CLS
INPUT “Enter any number”; n
CALL square (n)
END
SUB square (n)
r = sqr (n)
IF r = INT (r) THEN
PRINT n; “is a perfect square”
ELSE
PRINT n; “is not a perfect square”
END IF
END SUB
© atish shrestha
30. WAP to input any number and display the sum of its digits
using SUB….END SUB.
DECLARE SUB digsum (n)
CLS
INPUT “Enter any number”; n
CALL digsum (n)
END
SUB digsum (n)
WHILE n < > 0
r = n MOD 10
s = s + r
n = n \ 10
WEND
PRINT “the sum of digits= ”; s
END SUB
© atish shrestha
31. WAP to input any two positive integers and display LCM and HCF
of those integers using SUB….END SUB.
DECLARE SUB hcflcm (a, b)
CLS
INPUT “Enter first number”; a
INPUT “Enter second number”; b
CALL hcflcm (a, b)
END
SUB hcflcm (a, b)
x = a : y = b
WHILE x MOD y < > 0
r = x MOD y
x = y
y = r
WEND
hcf = y
lcm = (a*b)/hcf
PRINT “the hcf= ”; hcf
PRINT “the lcm= ”; lcm
END SUB
© atish shrestha
32. WAP to count the number of digits in a number entered by a
user using SUB….END SUB.
DECLARE SUB count (n)
CLS
INPUT “Enter any number”; n
CALL count (n)
END
SUB count (n)
WHILE n < > 0
r = n MOD 10
c = c + 1
n = n \ 10
WEND
PRINT “the number of digits= ”; c
END SUB
© atish shrestha
33. WAP to print three digits Armstrong numbers using SUB….END
SUB. (hint: 153, 370, 371, 407)
DECLARE SUB arm ( )
CLS
CALL arm
END
SUB arm
FOR i = 1 TO 9
s = i ^ 3
FOR j = 0 to 9
t = j ^ 3
FOR k = 0 TO 9
u = k ^ 3
n = k + j *10 + I * 100
m = s + t + u
IF m < > n THEN GOTO lab1
PRINT TAB (10); n
lab1:
next
next
next
END SUB
© atish shrestha
34. WAP to input decimal number and convert it into a binary number
using SUB….END SUB.
DECLARE SUB decbin (n)
CLS
INPUT “Enter any decimal number”; n
CALL decbin (n)
END
SUB decbin (n)
t = 0
p = 1
WHILE n < > 0
r = n MOD 2
t = t + r * p
p = p * 10
n = n \ 2
WEND
PRINT “binary number= ”; t
END SUB
© atish shrestha
35. WAP to input binary number and convert it into a decimal number
using SUB….END SUB.
DECLARE SUB bindec (n)
CLS
INPUT “Enter any binary number”; n
CALL bindec (n)
END
SUB bindec (n)
t = 0
p = 1
WHILE n < > 0
r = n MOD 10
t = t + (r * p)
p = p * 2
n = n \ 10
WEND
PRINT “decimal number= ”; t
END SUB
© atish shrestha
36. WAP to print the following pattern using SUB….END SUB.
G
O G R
R O G R A
P R O G R A M
DECLARE SUB pattern (a$)
CLS
a$ = “PROGRAM”
CALL pattern (a$)
END
SUB pattern (a$)
p = 4
e = 1
t = 40
FOR i = 1 TO 4
PRINT TAB (t); MID$(a$, p, e)
p = p – 1
e = e + 2
t = t - 1
NEXT i
END SUB
© atish shrestha
37. WAP to print the following pattern using SUB….END SUB.
P R O G R A M
R O G R A
O G R
G
DECLARE SUB pattern (s$)
CLS
CALL pattern (“PROGRAM”)
END
SUB pattern (s$)
p = 1
e = 7
t = 40
FOR i = 1 TO 4
PRINT TAB (t); MID$(s$, p, e)
p = p + 1
e = e - 2
t = t + 1
NEXT i
END SUB
© atish shrestha
38. WAP to strin (s$) to input a string and print whether initial
character is a number or uppercase or lowercase characters
using SUB….END SUB.
DECLARE SUB strin (s$)
CLS
INPUT “enter any string”; s$
CALL strin (s$)
END
SUB strin (s$)
l$ = MID$(s$, 1, 1)
a = ASC (l$)
IF l$ >= “0” AND l$<= “9” THEN
PRINT “initial character is a number”
ELSEIF a>=65 AND a<=90 THEN
PRINT “initial character is uppercase”
ELSEIF a>=97 AND a<=122 THEN
PRINT “initial character is lowecase”
END IF
END SUB
© atish shrestha
39. WAP hston ( ) to print 7 22 11 34 17 52 26
13 40 20 without passing parameter using SUB….END SUB.
DECLARE SUB hston ( )
CLS
CALL hston
END
SUB hston
a = 7
FOR i = 1 TO 10
PRINT a;
IF a MOD 2 = 0 THEN
a = a/2
ELSE
a = a * 3 + 1
END IF
NEXT i
END SUB
© atish shrestha
40. WAP factorial (n) to find the factorial of a given number
using SUB….END SUB. (n1 = 1 x 2 x 3 x …..n)
DECLARE SUB factorial (n)
CLS
INPUT “Enter any number”; n
CALL factorial (n)
END
SUB factorial (n)
f = 1
FOR i = 1 TO n
f = f * i
NEXT i
PRINT “the factorial of the given number= ”; f
END SUB
© atish shrestha
41. WAP to input any string and remove the vowels from the string using
SUB….END SUB.
DECLARE SUB revow (s$)
CLS
INPUT “Enter any string”; s$
CALL revow (s$)
END
SUB revow (s$)
FOR i = 1 TO LEN (s$)
v$ = MID$ (s$, i, 1 )
SELECT CASE UCASE$(v$)
CASE “A”, “E”, “I”, “O”, “U”
PRINT ;
CASE ELSE
PRINT v$
END SELECT
NEXT i
END SUB
© atish shrestha
42. WAP to display the prime numbers from 1 to 100 using SUB….END SUB.
DECLARE SUB prime ( )
CLS
CALL prime
END
SUB prime
FOR i = 2 TO 100
FOR j = 2 TO i – 1
IF i MOD j = 0 THEN GOTO last
NEXT j
PRINT i;
last:
NEXT i
END SUB
© atish shrestha
43. WAP to display the factors of a given number using FUNCTION…….END
FUNCTION.
DECLARE SUB factors (n)
CLS
INPUT “Enter any number”; n
CALL factors (n)
END
SUB factors (n)
FOR i = 1 TO n
r = n MOD i
If r = 0 THEN PRINT i;
NEXT i
END SUB
© atish shrestha
44. WAP to print the following output using SUB…END SUB.
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
DECLARE SUB pattern ( )
CLS
CALL pattern
END
SUB pattern
a = 1
FOR i = 1 TO 5
PRINT a * a
a = a * 10 + 1
NEXT i
END SUB
© atish shrestha