b.
WAP to input any number and check whether the given no. is positive, negative
or zero.
DECLARE FUNCTION CHECK$ (N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT N; "IS "; CHECK$(N)
END
FUNCTION CHECK$ (N)
IF N
> 0 THEN
CHECK$ = "POSITIVE NUMBER"
ELSEIF N
< 0 THEN
CHECK$ = "NEGATIVE NUMBER"
ELSE
CHECK$ = "ZERO"
END IF
END FUNCTION
c.
check even or odd number
DECLARE FUNCTION CHECK$ (N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT N; "IS "; CHECK$(N)
END
FUNCTION CHECK$ (N)
IF N MOD
2 = 0 THEN
CHECK$ = "EVEN NUMBER"
ELSE
CHECK$ = "ODD NUMBER"
END IF
END FUNCTION
d.
to print square of first 10 natural number
Declare function num()
CLS
a = num
END
FUNCTION num ()
FOR p =
1 TO 10
PRINT p ^ 2
NEXT p
END SUB
e. the sum of individual digits of multi digit input number.
DECLARE FUNCTION
SDIG(N)
CLS
INPUT”ENTER A NUMBER”; N
PRINT “SUM IS ” ; SDIG(N)
END
CLS
INPUT”ENTER A NUMBER”; N
PRINT “SUM IS ” ; SDIG(N)
END
FUNCTION SDIG(N)
WHILE N<>0
R=N MOD 10
S=S+R
N=N\10
WEND
SDIG=S
END FUNCTION
WHILE N<>0
R=N MOD 10
S=S+R
N=N\10
WEND
SDIG=S
END FUNCTION
Solve
a quadratic equation ax2+bx+c=0 on the basis of the coefficient values a, b,
and c.
REM SOLVE A QUADRATIC EQUATION
CLS
INPUT "ENTER VALUE FOR A"; A
INPUT "ENTER VALUE FOR B"; B
INPUT "ENTER VALUE FOR C"; C
D = (B * B - 4 * A * C) ^ (1 / 2)
X = (-B + D) / 2 * A
Y = (-B - D) / 2 * A
PRINT "SOLUTION OF QUADRATIC EQUATION ARE"; X; Y
END
USING SUB PROCEDURE
DECLARE SUB EQUATION (A, B, C)
CLS
INPUT "ENTER VALUE FOR A"; A
INPUT "ENTER VALUE FOR B"; B
INPUT "ENTER VALUE FOR C"; C
CALL EQUATION (A, B, C)
END
SUB EQUATION (A, B, C)
D = (B * B - 4 * A * C) ^ (1 / 2)
X = (-B + D) / 2 * A
Y = (-B - D) / 2 * A
PRINT "SOLUTION OF QUADRATIC EQUATION ARE"; X; Y
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION EQUATION (A, B, C)
COMMON SHARED X
CLS
INPUT "ENTER VALUE FOR A"; A
INPUT "ENTER VALUE FOR B"; B
INPUT "ENTER VALUE FOR C"; C
PRINT "SOLUTION OF QUADRATIC EQUATION ARE"; X;
EQUATION(A, B, C)
END
FUNCTION EQUATION (A, B, C)
D = (B * B - 4 * A * C) ^ (1 / 2)
X = (-B + D) / 2 * A
Y = (-B - D) / 2 * A
EQUATION =Y
END FUNCTION
Write a program to calculate the volume of a
cylinder using FUNCTION……END FUNCTION. [PI*R^2*H]
DECLARE FUNCTION VOL(R,H)
CLS
CONST PI=3.14
INPUT “Enter radius and height”; R, H
PRINT “The volume=”; VOL(R,H)
END
FUNCTION VOL(R,H)
V=PI*R^2*H
VOL=V
END FUNCTION
Write a program to print the following series:
1,4,7,……. up to 10th term using FUNCTION……END FUNCTION.
DECLARE FUNCTION SERIES
CLS
D= SERIES
END
FUNCTION SERIES
FOR I = 1 TO 10
PRINT A;
A=A+3
NEXT I
END FUNCTION
Write a program to display greater number among any
two numbers using FUNCTION……. END FUNCTION.
DECLARE FUNCTION GREAT(A,B)
CLS
INPUT “Enter any two number”; A,B
PRINT “The greater number is”; GREAT(A,B)
END
FUNCTION GREAT(A,B)
IF A>B THEN
GREAT= A
ELSE
GREAT=B
END IF
END FUNCTION
Write a program to find the factorial of number using
FUNCTION…… END FUNCTION.
DECLARE FUNCTION FACT(N)
CLS
INPUT “Enter a non-negative number”; N
PRINT “The factorial of given number is”; FACT(N)
END
FUNCTION FACT(N)
F=1
FOR I =1 TO N
F=F*I
NEXT I
FACT=F
END FUNCTION
Write a program to display vowels and consonants of
the entered string by using FUNCTION …….. END FUNCTION.
DECLARE FUNCTION VOW(S$)
DECLARE FUNCTION VOW(S$)
DECLARE FUNCTION CON(S$)
CLS
INPUT “Enter a word”; S$
VO= VOW(S$)
CO= CON(S$)
END
FUNCTION VOW(S$)
PRINT “The vowels are”
FOR I = 1 TO LEN(S$)
B$=MID$(S$,I,1)
C$=UCASE$(B$)
IF C$= “A” OR C$= “E” OR C$= “I” OR C$= “O” OR C$=”U”
THEN
PRINT B$
NEXT I
END FUNCTION
FUNCTION CON(S$)
PRINT “The consonant are”
FOR I = 1 TO LEN(S$)
B$=MID$(S$,I,1)
C$= UCASE$(B$)
IF C$<> “A” AND C$<> “E” AND C$<>
“I” AND C$<> “O” AND C$<> “U” THEN
PRINT B$
NEXT I
END FUNCTION
Write a program to declare a user defined function to
return a given number in reverse order by using FUNCTION…… END FUNCTION.
DECLARE FUNCTION REV(N)
CLS
INPUT “Enter a number”; N
PRINT “The reverse form is”; REV(N)
END
FUNCTION REV(N)
S=0
WHILE N<>0
R=N MOD 10
S=S*10+R
N=N\10
WEND
REV=S
END FUNCTION
WAP to input number and count total no. of digits.
REM
CLS
INPUT "ENTER ANY NUMBER"; N
C = 0
WHILE N < > 0
C = C + 1
N = N \ 10
WEND
PRINT "TOTAL NUMBER OF DIGITS"; C
END
USING SUB PROCEDURE
DECLARE SUB COUNT (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL COUNT (N)
END
SUB COUNT (N)
C = 0
WHILE N < > 0
C = C + 1
N = N \ 10
WEND
PRINT "TOTAL NUMBER OF DIGITS"; C
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION COUNT (N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "TOTAL NUMBER OF DIGITS"; COUNT (N)
END
FUNCTION SUM (N)
C = 0
WHILE N < > 0
C = C + 1
N = N \ 10
WEND
COUNT = C
END FUNCTION
WAP to input number and count total no. of odd digits.
REM
CLS
INPUT "ENTER ANY NUMBER"; N
C = 0
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 1 THEN C = C + 1
N = N \ 10
WEND
PRINT "TOTAL NUMBER OF ODD DIGITS"; C
END
USING SUB PROCEDURE
DECLARE SUB COUNT (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL COUNT (N)
END
SUB COUNT (N)
C = 0
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 1 THEN C = C + 1
N = N \ 10
WEND
PRINT "TOTAL NUMBER OF ODD DIGITS"; C
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION COUNT (N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "TOTAL NUMBER OF ODD DIGITS"; COUNT (N)
END
FUNCTION SUM (N)
C = 0
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 1 THEN C = C + 1
N = N \ 10
WEND
COUNT = C
END FUNCTION
WAP to input number and count total no. of even
digits.
REM
CLS
INPUT "ENTER ANY NUMBER"; N
C = 0
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 0 THEN C = C + 1
N = N \ 10
WEND
PRINT "TOTAL NUMBER OF EVEN DIGITS"; C
END
USING SUB PROCEDURE
DECLARE SUB COUNT (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL COUNT (N)
END
SUB COUNT (N)
C = 0
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 0 THEN C = C + 1
N = N \ 10
WEND
PRINT "TOTAL NUMBER OF EVEN DIGITS"; C
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION COUNT (N)
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "TOTAL NUMBER OF EVEN DIGITS"; COUNT (N)
END
FUNCTION SUM (N)
C = 0
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 0 THEN C = C + 1
N = N \ 10
WEND
COUNT = C
END FUNCTION
WAP TO ENTER ANY DIGIT AND DISPLAY EVEN
DIGITS
REM
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "EVEN DIGITS ARE ";
WHILE N <> 0
R = N MOD 10
IF R MOD 2 = 0 THEN PRINT R;
N = N \ 10
WEND
END
USING SUB PROCEDURE
DECLARE SUB EVEN (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL EVEN (N)
END
SUB EVEN (N)
PRINT "EVEN DIGITS ARE ";
WHILE N <> 0
R = N MOD 10
IF R MOD 2 = 0 THEN PRINT R;
N = N \ 10
WEND
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION EVEN (N)
REM
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "EVEN DIGITS ARE ";
D = EVEN(N)
END
FUNCTION EVEN (N)
WHILE N <> 0
R = N MOD 10
IF R MOD 2 = 0 THEN PRINT R;
N = N \ 10
WEND
END FUNCTION
WAP TO ENTER ANY DIGIT AND DISPLAY SQUARE OF
ODD DIGITS
REM
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SQUARE OF ODD DIGITS ARE ";
WHILE N <> 0
R = N MOD 10
IF R MOD 2 = 1 THEN PRINT R ^ 2;
N = N \ 10
WEND
END
USING SUB PROCEDURE
DECLARE SUB ODD (N)
CLS
INPUT "ENTER ANY NUMBER"; N
CALL ODD (N)
END
SUB ODD (N)
PRINT " SQUARE OF ODD DIGITS ARE ";
WHILE N <> 0
R = N MOD 10
IF R MOD 2 = 1 THEN PRINT R ^ 2;
N = N \ 10
WEND
END SUB
USING FUNCTION PROCEDURE
DECLARE FUNCTION ODD (N)
REM
CLS
INPUT "ENTER ANY NUMBER"; N
PRINT "SQUARE OF ODD DIGITS";
D = ODD(N)
END
FUNCTION ODD (N)
WHILE N <> 0
R = N MOD 10
IF R MOD 2 = 1 THEN PRINT R ^ 2;
N = N \ 10
WEND
END FUNCTION
To
display the ASCII value of the character entered.
CLS
INPUT "Enter a character"; a$
a = ASC(a$)
PRINT "The ASCII equivalent is"; a
END
CLS
INPUT "Enter a character"; a$
a = ASC(a$)
PRINT "The ASCII equivalent is"; a
END
To Check The Word Palindrome Or Not
Using FUNCTION
procedure
DECLARE FUNCTION palindrome$ (w$)
CLS
INPUT "Enter any word"; w$
a$ = w$
IF a$ = palindrome$(w$) THEN
PRINT w$; " is palindrome word";
ELSE
PRINT w$; " is not palindrome word";
END IF
FUNCTION palindrome$ (w$)
FOR i = LEN(w$) TO 1 STEP -1
rev$ = rev$ + MID$(w$, i, 1)
NEXT i
palindrome$ = rev$
END FUNCTION
DECLARE FUNCTION palindrome$ (w$)
CLS
INPUT "Enter any word"; w$
a$ = w$
IF a$ = palindrome$(w$) THEN
PRINT w$; " is palindrome word";
ELSE
PRINT w$; " is not palindrome word";
END IF
FUNCTION palindrome$ (w$)
FOR i = LEN(w$) TO 1 STEP -1
rev$ = rev$ + MID$(w$, i, 1)
NEXT i
palindrome$ = rev$
END FUNCTION
To
print input string in alternate capital letters. (if user inputs 'COMPUTER' or
'computer' then the output should be 'CoMpUtEr')
CLS
INPUT "Enter string:"; a$
FOR i = 1 TO LEN(a$)
b$ = MID$(a$, i, 1)
IF i MOD 2 = 0 THEN
b$ = LCASE$(b$)
ELSE
b$ = UCASE$(b$)
END IF
alt$ = alt$ + b$
NEXT i
PRINT "The required alternate is: "; alt$
END
CLS
INPUT "Enter string:"; a$
FOR i = 1 TO LEN(a$)
b$ = MID$(a$, i, 1)
IF i MOD 2 = 0 THEN
b$ = LCASE$(b$)
ELSE
b$ = UCASE$(b$)
END IF
alt$ = alt$ + b$
NEXT i
PRINT "The required alternate is: "; alt$
END
USING FUNCTION
DECLARE FUNCTION alternate$(a$)
CLS
INPUT "Enter string:"; a$
PRINT "The required alternate is: "; alternate$(a$)
END
FUNCTION alternate$ (a$)
FOR i = 1 TO LEN(a$)
b$ = MID$(a$, i, 1)
IF i MOD 2 = 0 THEN
b$ = LCASE$(b$)
ELSE
b$ = UCASE$(b$)
END IF
alt$ = alt$ + b$
NEXT i
alternate$ = alt$
'PRINT "The required alternate is: "; alt$
END FUNCTION
CLS
INPUT "Enter string:"; a$
PRINT "The required alternate is: "; alternate$(a$)
END
FUNCTION alternate$ (a$)
FOR i = 1 TO LEN(a$)
b$ = MID$(a$, i, 1)
IF i MOD 2 = 0 THEN
b$ = LCASE$(b$)
ELSE
b$ = UCASE$(b$)
END IF
alt$ = alt$ + b$
NEXT i
alternate$ = alt$
'PRINT "The required alternate is: "; alt$
END FUNCTION
USING SUB
DECLARE SUB alternate (a$)
CLS
INPUT "Enter string:"; a$
CALL alternate (a$)
END
SUB alternate (a$)
FOR i = 1 TO LEN (a$)
b$ = MID$ (a$, i, 1)
IF i MOD 2 = 0 THEN
b$ = LCASE$ (b$)
ELSE
b$ = UCASE$ (b$)
END IF
alt$ = alt$ + b$
NEXT i
PRINT "The required alternate is: "; alt$
END SUB
CLS
INPUT "Enter string:"; a$
CALL alternate (a$)
END
SUB alternate (a$)
FOR i = 1 TO LEN (a$)
b$ = MID$ (a$, i, 1)
IF i MOD 2 = 0 THEN
b$ = LCASE$ (b$)
ELSE
b$ = UCASE$ (b$)
END IF
alt$ = alt$ + b$
NEXT i
PRINT "The required alternate is: "; alt$
END SUB
Program to print the short form of the name
CLS
INPUT "Enter your first, middle and last name "; n$
b$ = UCASE$(MID$(n$, 1, 1))
w$ = w$ + b$ + "."
a$ = a$ + b$
FOR i = 2 TO LEN(n$)
b$ = UCASE$(MID$(n$, i, 1))
IF RIGHT$(a$, 1) = " " THEN w$ = w$ + b$ + "."
a$ = a$ + b$
NEXT
PRINT w$
END
CLS
INPUT "Enter your first, middle and last name "; n$
b$ = UCASE$(MID$(n$, 1, 1))
w$ = w$ + b$ + "."
a$ = a$ + b$
FOR i = 2 TO LEN(n$)
b$ = UCASE$(MID$(n$, i, 1))
IF RIGHT$(a$, 1) = " " THEN w$ = w$ + b$ + "."
a$ = a$ + b$
NEXT
PRINT w$
END
Palindrome number
USING FUNCTION PROCEDURE
DECLARE FUNCTION PALIN (N)
CLS
INPUT "ENTER ANY NUMBER"; N
P = PALIN ((N))
IF P = N THEN
PRINT N; "IS PALINDROME"
ELSE
PRINT N; "IS NOT PALINDROME"
END IF
END
FUNCTION PALIN (N)
S = 0
WHILE N < > 0
R = N MOD 10
S = S * 10 + R
N = N \ 10
WEND
PALIN = S
END FUNCTION
Armstrong number
USING FUNCTION PROCEDURE
DECLARE FUNCTION ARM (N)
CLS
INPUT "ENTER ANY NUMBER"; N
A=N
AR = ARM (N)
IF A = AR THEN
PRINT A; "IS ARMSTRONG NUMBER"
ELSE
PRINT A; "IS NOT ARMSTRONG NUMBER"
END IF
END
FUNCTION ARM (N)
S = 0
WHILE N < > 0
R = N MOD 10
S = S + R ^ 3
N = N \ 10
WEND
ARM = S
END FUNCTION
No comments:
Post a Comment