Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Tuesday, February 8, 2022

Methods of calling FUNCTION in QBASIC

 Methods of Calling FUNCTION in QBASIC

 

By using  “Expression method”
1.  WAP to display the sum of input two numbers.
DECLARE FUNCTION sum (a, b)
CLS
INPUT "enter any two numbers"; a, b
s = sum(a, b)
PRINT "Sum of two numbers"; s
END
FUNCTION sum (a, b)
sum = a + b
END FUNCTION
 
Function called by using “statement method”
2.  WAP to display the string in reverse order.
DECLARE FUNCTION re$ (w$)
CLS
INPUT "enter any string"; w$
r$ = re$(w$)
PRINT r$
END
 
FUNCTION re$ (w$)
FOR x = LEN(w$) TO 1 STEP -1
m$ = m$ + MID$(w$, x, 1)
NEXT
re$ = m$
END FUNCTION
 
Function called by using “Constant value”
3.  WAP to display the average of two numbers.
DECLARE FUNCTION avg (a, b)
CLS
s = avg(13, 23)
PRINT "average of two numbers"; s
END
FUNCTION avg (a, b)
avg = (a + b) / 2
END FUNCTION
 
Function input numeric value and return string value
4.  WAP to input any number and display whether input number is add or even
DECLARE FUNCTION oes$ (n)
CLS
INPUT "Enter any number"; n
e$ = oes$(n)
PRINT "The number is="; e$
END
 
FUNCTION oes$ (n)
r = n MOD 2
IF r = 0 THEN
oes$ = "even"
ELSE
oes$ = "odd"
END IF
END FUNCTION
 
Function input string and returns numeric value
5.  WAP to input any string and count total vowels letters.
DECLARE FUNCTION vow (w$)
CLS
INPUT "Enter any string"; w$
PRINT "Total vowel letters="; vow(w$)
END
 
FUNCTION vow (w$)
FOR x = 1 TO LEN(w$)
m$ = MID$(w$, x, 1)
SELECT CASE m$
CASE "a", "e", "i", "o", "u"
v = v + 1
END SELECT
NEXT
vow = v
END FUNCTION
 
Array can be passed to the function as an argument
6. WAP to input 5 different numbers in any array variable and display the sum of given numbers.
DECLARE FUNCTION arr (n())
CLS
DIM n(5)
PRINT "Enter five  number"
FOR x = 1 TO 5
INPUT n(x)
NEXT
s = arr(n())
PRINT "sum="; s
END
 
FUNCTION arr (n())
FOR x = 1 TO 5
su = su + n(x)
NEXT
arr = su
END FUNCTION

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages