Area of circle(SUB)
DECLARE SUB AREA ( R )
CLS
INPUT "Enter radius"; R
CALL AREA (R)
END
SUB AREA (R)
A = 22 / 7 * R ^ 2
PRINT "Area of circle ="; A
END SUB
CLS
INPUT "Enter radius"; R
CALL AREA (R)
END
SUB AREA (R)
A = 22 / 7 * R ^ 2
PRINT "Area of circle ="; A
END SUB
Count total no.of
words in a sentence (FUNCTION)
DECLARE FUNCTION COUNT
(A$)
CLS
INPUT " Enter a sentence"; A$
PRINT " Total no. of words ="; COUNT (A$)
END
FUNCTION COUNT(A$)
C = 0
FOR I = 1 TO LEN (A$)
B$ = MID$ (A$, I, 1)
C$ = UCASE$ (B$)
IF B$ =" " THEN C = C + 1
NEXT I
COUNT = C
END FUNCTION
CLS
INPUT " Enter a sentence"; A$
PRINT " Total no. of words ="; COUNT (A$)
END
FUNCTION COUNT(A$)
C = 0
FOR I = 1 TO LEN (A$)
B$ = MID$ (A$, I, 1)
C$ = UCASE$ (B$)
IF B$ =" " THEN C = C + 1
NEXT I
COUNT = C
END FUNCTION
Area of 4 walls(SUB)
DECLARE SUB AREA (L,
B, H )
CLS
INPUT " Enter length "; L
INPUT " Enter breadth "; B
INPUT " Enter height "; H
CALL AREA (L, B, H)
END
SUB AREA ( L, B, H)
A = 2 * H * ( L + B )
PRINT "Area of 4 walls ="; A
END SUB
CLS
INPUT " Enter length "; L
INPUT " Enter breadth "; B
INPUT " Enter height "; H
CALL AREA (L, B, H)
END
SUB AREA ( L, B, H)
A = 2 * H * ( L + B )
PRINT "Area of 4 walls ="; A
END SUB
Total no. of vowels in
given words (FUNCTION)
DECLARE FUNCTION COUNT
(N$)
CLS
INPUT " Enter any word ";N$
PRINT "Total no. of vowels ="; COUNT (N$)
END
FUNCTION COUNT (N$)
C = 0
FOR I = 1 TO LEN (N$)
B$ = MID$ ( N$, I, 1)
C$ = UCASE$(B$)
IF C$ = "A" OR C$ = "E" OR C$ = "I" OR C$="O" OR C$ = "U" THEN C=C+1
NEXT I
COUNT = C
END FUNCTION
CLS
INPUT " Enter any word ";N$
PRINT "Total no. of vowels ="; COUNT (N$)
END
FUNCTION COUNT (N$)
C = 0
FOR I = 1 TO LEN (N$)
B$ = MID$ ( N$, I, 1)
C$ = UCASE$(B$)
IF C$ = "A" OR C$ = "E" OR C$ = "I" OR C$="O" OR C$ = "U" THEN C=C+1
NEXT I
COUNT = C
END FUNCTION
Display reverse of
input string (SUB)
DECLARE SUB REV$ (N$)
CLS
INPUT "ENTER A STRING "; N$
CALL REV$(N$)
END
SUB REV$ (N$)
FOR I = LEN(N$) TO 1 STEP -1
B$ = MID$( N$, I, 1)
D$=D$+B$
NEXT I
REV$=D$
END FUNCTION
CLS
INPUT "ENTER A STRING "; N$
CALL REV$(N$)
END
SUB REV$ (N$)
FOR I = LEN(N$) TO 1 STEP -1
B$ = MID$( N$, I, 1)
D$=D$+B$
NEXT I
REV$=D$
END FUNCTION
Area of triangle
(FUNCTION)
DECLARE FUNCTION AREA
(L, B)
CLS
INPUT " ENTER LENGTH "; L
INPUT " ENTER BREADTH "; B
PRINT " AREA OF TRIANGLE = "; AREA ( L, B )
END
FUNCTION AREA ( L, B)
A = 1/2 * B * H
AREA = A
END FUNCTION
CLS
INPUT " ENTER LENGTH "; L
INPUT " ENTER BREADTH "; B
PRINT " AREA OF TRIANGLE = "; AREA ( L, B )
END
FUNCTION AREA ( L, B)
A = 1/2 * B * H
AREA = A
END FUNCTION
Volume of cylinder (FUNCTION)
DECLARE FUNCTION VOL (
R , H )
CLS
INPUT " Enter radius "; R
INPUT " Enter height"; H
PRINT "Volume of cylinder ="; VOL (R, H )
END
FUNCTION VOL( R, H)
V = 22 / 7 * R ^ 2 * H
VOL = V
END FUNCTION
CLS
INPUT " Enter radius "; R
INPUT " Enter height"; H
PRINT "Volume of cylinder ="; VOL (R, H )
END
FUNCTION VOL( R, H)
V = 22 / 7 * R ^ 2 * H
VOL = V
END FUNCTION
Print first 10 odd
numbers(SUB)
DECLARE SUB SERIES
( )
CLS
CALL SUB SERIES
END
SUB SERIES ( )
A = 1
FOR I = 1 TO 10
PRINT A
A = A + 2
NEXT I
END SUB
CLS
CALL SUB SERIES
END
SUB SERIES ( )
A = 1
FOR I = 1 TO 10
PRINT A
A = A + 2
NEXT I
END SUB
Count the total no. of
consonants(FUNCTION)
DECLARE FUNCTION COUNT
(N$)
CLS
INPUT “ENTER ANY STRING”; N$
PRINT “TOTAL NO. OF CONSONANTS= “; COUNT(N$)
END
FUNCTION COUNT (N$)
C = 0
FOR I = 1 TO LEN(N$)
B$ = MID$(N$, I, 1)
C$ = UCASE$(B$)
IF C$ < > “A” AND C$ < > “E”AND C$ < > “I” AND C$ < >“O” AND C$ < >“U” THEN C = C + 1
NEXT I
COUNT = C
END FUNCTION
CLS
INPUT “ENTER ANY STRING”; N$
PRINT “TOTAL NO. OF CONSONANTS= “; COUNT(N$)
END
FUNCTION COUNT (N$)
C = 0
FOR I = 1 TO LEN(N$)
B$ = MID$(N$, I, 1)
C$ = UCASE$(B$)
IF C$ < > “A” AND C$ < > “E”AND C$ < > “I” AND C$ < >“O” AND C$ < >“U” THEN C = C + 1
NEXT I
COUNT = C
END FUNCTION
Sum of digits(SUB)
DECLARE SUB SUM( N)
CLS
INPUT " ENTER ANY DIGIT"; N
CALL SUM ( N)
END
SUB SUM (N)
S = 0
WHILE N<> 0
R = N MOD 10
S = S + R
N = N \10
WEND
PRINT " SUM OF DIGIT ="; S
END SUB
CLS
INPUT " ENTER ANY DIGIT"; N
CALL SUM ( N)
END
SUB SUM (N)
S = 0
WHILE N<> 0
R = N MOD 10
S = S + R
N = N \10
WEND
PRINT " SUM OF DIGIT ="; S
END SUB
Convert temperature in
celcius in farenheit (FUNCTION)
DECLARE FUNCTION
CONVERT(C)
CLS
INPUT "ENTER CELCIUS "; C
PRINT "CELCIUS TO FAHRENHEIT ";CONVERT(C)
END
FUNCTION CONVERT(C)
F =9 *C / 5+32
CONVERT = F
END FUNCTION
CLS
INPUT "ENTER CELCIUS "; C
PRINT "CELCIUS TO FAHRENHEIT ";CONVERT(C)
END
FUNCTION CONVERT(C)
F =9 *C / 5+32
CONVERT = F
END FUNCTION
Print simple interest
(FUNCTION)
DECLARE FUNCTION SI (P
,T ,R )
CLS
INPUT "ENTER PRINCIPAL "; P
INPUT "ENTER RATE "; R
INPUT" ENTER TIME ";T
PRINT "SIMPLE INTEREST ";SI (P ,T ,R )
END
FUNCTION SI (P , T ,R )
I= P *T *R/100
SI = I
END FUNCTION
CLS
INPUT "ENTER PRINCIPAL "; P
INPUT "ENTER RATE "; R
INPUT" ENTER TIME ";T
PRINT "SIMPLE INTEREST ";SI (P ,T ,R )
END
FUNCTION SI (P , T ,R )
I= P *T *R/100
SI = I
END FUNCTION
Display 1,1,2,3,5,8……upto
10 terms (SUB)
DECLARE SUB SERIES ( )
CLS
CALL SERIES
END
SUB SERIES ( )
A= 1
B= 1
FOR I= 1 TO 5
PRINT A
PRINT B
A= A+B
B= A+B
NEXT I
END SUB
CLS
CALL SERIES
END
SUB SERIES ( )
A= 1
B= 1
FOR I= 1 TO 5
PRINT A
PRINT B
A= A+B
B= A+B
NEXT I
END SUB
Natural no. from 1 to 5
(SUB)
DECLARE SUB SERIES ( )
CLS
CALL SERIES
END
SUB SERIES ()
FOR I = 1 TO 5
PRINT I
NEXT I
END SUB
CLS
CALL SERIES
END
SUB SERIES ()
FOR I = 1 TO 5
PRINT I
NEXT I
END SUB
Display greatest among
three no.(SUB)
DECLARE SUB GREATEST
(A, B, C)
CLS
INPUT" ENTER ANY THREE NUMBERS"; A, B, C
CALL GREATEST (A, B, C)
END
SUB GREATEST (A, B, C)
IF A> B AND A> C THEN
PRINT"THE GREATEST NUMBER IS"; A
ELSEIF B>A AND B> C THEN
PRINT"THE GREATEST NUMBER IS"; B
ELSE
PRINT"THE GREATEST NUMBER IS";C
END IF
END SUB
CLS
INPUT" ENTER ANY THREE NUMBERS"; A, B, C
CALL GREATEST (A, B, C)
END
SUB GREATEST (A, B, C)
IF A> B AND A> C THEN
PRINT"THE GREATEST NUMBER IS"; A
ELSEIF B>A AND B> C THEN
PRINT"THE GREATEST NUMBER IS"; B
ELSE
PRINT"THE GREATEST NUMBER IS";C
END IF
END SUB
Area of a
box(FUNCTION)
DECLARE FUNCTION AREA
(L, B, H)
CLS
INPUT" ENTER LENGTH"; L
INPUT" ENTER BREADTH"; B
INPUT" ENTER HEIGHT"; H
PRINT" AREA OF THE BOX"; AREA (L, B, H)
END
FUNCTION AREA (L, B, H)
A= 2 *(L*H + B*H + L*B)
AREA= A
END FUNCTION
CLS
INPUT" ENTER LENGTH"; L
INPUT" ENTER BREADTH"; B
INPUT" ENTER HEIGHT"; H
PRINT" AREA OF THE BOX"; AREA (L, B, H)
END
FUNCTION AREA (L, B, H)
A= 2 *(L*H + B*H + L*B)
AREA= A
END FUNCTION
Area of 4
walls(FUNCTION)
DECLARE FUNCTION AREA
(L, B, H)
CLS
INPUT " ENTER LENGTH "; L
INPUT " ENTER BREADTH "; B
INPUT " ENTER HEIGHT "; H
PRINT " AREA OF 4 WALLS "; AREA (L, B, H)
END
FUNCTION AREA(L, B, H)
A= 2 * H * ( L + B)
AREA= A
END FUNCTION
CLS
INPUT " ENTER LENGTH "; L
INPUT " ENTER BREADTH "; B
INPUT " ENTER HEIGHT "; H
PRINT " AREA OF 4 WALLS "; AREA (L, B, H)
END
FUNCTION AREA(L, B, H)
A= 2 * H * ( L + B)
AREA= A
END FUNCTION
Circumference of
circle(SUB)
DECLARE SUB CIR(R)
CLS
INPUT " ENTER RADIUS "; R
CALL CIR(R)
END
SUB CIR(R)
C= 2 * 22/7 * R
PRINT " CIRCUMFERENCE OF CIRCLE ="; C
END SUB
CLS
INPUT " ENTER RADIUS "; R
CALL CIR(R)
END
SUB CIR(R)
C= 2 * 22/7 * R
PRINT " CIRCUMFERENCE OF CIRCLE ="; C
END SUB
To check whether the
given no. is divisible by 13 or not .(SUB)
DECLARE SUB CHECK(N)
CLS
INPUT"ENTER ANY NUMBER"; N
CALL CHECK(N)
END
SUB CHECK(N)
IF N MOD 13 = 0 THEN
PRINT" THE GIVEN NUMBER IS DIVISIBLE BY 13 "
ELSE
PRINT" THE GIVEN NUMBER IS NOT DIVISIBLE BY 13"
END IF
END SUB
CLS
INPUT"ENTER ANY NUMBER"; N
CALL CHECK(N)
END
SUB CHECK(N)
IF N MOD 13 = 0 THEN
PRINT" THE GIVEN NUMBER IS DIVISIBLE BY 13 "
ELSE
PRINT" THE GIVEN NUMBER IS NOT DIVISIBLE BY 13"
END IF
END SUB
Volume of
box(FUNCTION)
DECLARE FUNCTION
VOLUME (L, B, H)
CLS
INPUT " ENTER LENGTH "; L
INPUT " ENTER BREADTH " ; B
INPUT " ENTER HEIGHT "; H
PRINT " VOLUME OF BOX "; VOLUME (L, B, H)
END
FUNCTION VOLUME (L, B, H)
V= L * B * H
VOLUME = V
END FUNCTION
CLS
INPUT " ENTER LENGTH "; L
INPUT " ENTER BREADTH " ; B
INPUT " ENTER HEIGHT "; H
PRINT " VOLUME OF BOX "; VOLUME (L, B, H)
END
FUNCTION VOLUME (L, B, H)
V= L * B * H
VOLUME = V
END FUNCTION
Print only vowels from
given words(SUB)
DECLARE SUB DISP (A$)
CLS
INPUT " ENTER A WORD ";A$
CALL DISP (A$)
END
SUB DISP (A$)
FOR I = 1 TO LEN(A$)
B$ = MID (A$ , I, 1)
C$ = UCASE$(B$)
IF C$ = "A" OR C$ = "E" OR C$ = "I" OR C$ = "O" OR C$ = "U" THEN V$=V$ + C$
NEXT I
PRINT V$
END SUB
CLS
INPUT " ENTER A WORD ";A$
CALL DISP (A$)
END
SUB DISP (A$)
FOR I = 1 TO LEN(A$)
B$ = MID (A$ , I, 1)
C$ = UCASE$(B$)
IF C$ = "A" OR C$ = "E" OR C$ = "I" OR C$ = "O" OR C$ = "U" THEN V$=V$ + C$
NEXT I
PRINT V$
END SUB
Disrance travelled by
a body (FUNCTION)
DECLARE FUNCTION DIS
(U,T,A)
CLS
INPUT " ENTER ACCELERATION";A
INPUT " ENTER TIME";T
INPUT " ENTER INITIAL VELOCITY";U
PRINT " DISTANCE TRAVELED BY BODY =";DIS(U,T,A)
END
FUNCTION DIS (U,T,A)
D = U * T + 1 / 2 * A * T ^ 2
DIS = D
END FUNCTION
CLS
INPUT " ENTER ACCELERATION";A
INPUT " ENTER TIME";T
INPUT " ENTER INITIAL VELOCITY";U
PRINT " DISTANCE TRAVELED BY BODY =";DIS(U,T,A)
END
FUNCTION DIS (U,T,A)
D = U * T + 1 / 2 * A * T ^ 2
DIS = D
END FUNCTION
Display 9,7,5……1(SUB)
DECLARE SUB SERIES( )
CLS
CALL SERIES
END
SUB SERIES( )
FOR I = 9 TO 1 STEP -2
PRINT I
NEXT I
END SUB
CLS
CALL SERIES
END
SUB SERIES( )
FOR I = 9 TO 1 STEP -2
PRINT I
NEXT I
END SUB
Check positive or
negative (SUB)
DECLARE SUB CHECK(N)
CLS
INPUT " ENTER THE NUMBER";N
CALL CHECK(N)
END
SUB CHECK(N)
IF N > 0 THEN
PRINT "THE GIVEN NO IS POSITIVE"
ELSEIF N < 0 THEN
PRINT "THE GIVEN NO IS NEGATIVE"
ELSE
PRINT "THE GIVEN NO. IS ZERO "
END IF
END SUB
CLS
INPUT " ENTER THE NUMBER";N
CALL CHECK(N)
END
SUB CHECK(N)
IF N > 0 THEN
PRINT "THE GIVEN NO IS POSITIVE"
ELSEIF N < 0 THEN
PRINT "THE GIVEN NO IS NEGATIVE"
ELSE
PRINT "THE GIVEN NO. IS ZERO "
END IF
END SUB
Factorial(FUNCTION)
DECLARE FUNCTION
FACT(N)
CLS
INPUT " ENTER ANY NUMBER ";N
PRINT "FACTORIAL=";FACT(N)
END
FUNCTION FACT(N)
F = 1
FOR I = 1 TO N
F = F * I
NEXT I
FACT = F
END FUNCTION
CLS
INPUT " ENTER ANY NUMBER ";N
PRINT "FACTORIAL=";FACT(N)
END
FUNCTION FACT(N)
F = 1
FOR I = 1 TO N
F = F * I
NEXT I
FACT = F
END FUNCTION
Prime or composite
(SUB)
DECLARE SUB CHECK(N)
CLS
INPUT "ENTER ANY NUMBER";N
CALL CHECK(N)
END
FUNCTION CHECK(N)
C=0
FOR I = 1 TO N
IF N MOD I =0 THEN C = C+1
NEXT I
IF C = 2 THEN
PRINT "THE GIVEN NO IS PRIME"
ELSE
PRINT "THE GIVEN NO IS COMPOSITE"
END IF
END SUB
CLS
INPUT "ENTER ANY NUMBER";N
CALL CHECK(N)
END
FUNCTION CHECK(N)
C=0
FOR I = 1 TO N
IF N MOD I =0 THEN C = C+1
NEXT I
IF C = 2 THEN
PRINT "THE GIVEN NO IS PRIME"
ELSE
PRINT "THE GIVEN NO IS COMPOSITE"
END IF
END SUB
DECLARE FUNCTION
CHECK$(N$)
CLS
INPUT " ENTER ANY WORD "; N$
P$ = N$
IF P$ = CHECK$(N$) THEN
PRINT "The given word is palindrome "
ELSE
PRINT " The given word is not palindrome"
END IF
END
FUNCTION CHECK$ (N$)
FOR I = LEN(N$) TO 1 STEP -1
B$ = MID$ (N$, I,1)
C$ = C$ + B$
NEXT I
CHECK$ = C$
END FUNCTION
CLS
INPUT " ENTER ANY WORD "; N$
P$ = N$
IF P$ = CHECK$(N$) THEN
PRINT "The given word is palindrome "
ELSE
PRINT " The given word is not palindrome"
END IF
END
FUNCTION CHECK$ (N$)
FOR I = LEN(N$) TO 1 STEP -1
B$ = MID$ (N$, I,1)
C$ = C$ + B$
NEXT I
CHECK$ = C$
END FUNCTION
Display 50,42,35,29,24….10th
terms (SUB)
DECLARE SUB SERIES( )
CLS
CALL SERIES
END
SUB SERIES( )
A=50
B=8
FOR I = 1 TO 10
PRINT A
A=A-B
B=B-1
NEXT I
END SUB
A=50
B=8
FOR I = 1 TO 10
PRINT A
A=A-B
B=B-1
NEXT I
END SUB
Check input character
is capital or small(FUNCTION)
DECLARE FUNCTION
CHARC$(N$)
CLS
INPUT"ENTER ANY CHARACTER";N$
PRINT CHARC$(N$)
END
FUNCTION CHARC$(N$)
B$ = LEFT$(N$)
A = ASC(B$)
IF A >= 67 AND A<=95 THEN
CHARACTER$="LETTER IS IN UPPER CASE"
ELSE IF A >= 45 AND A <= 57 THEN
CHARACTER$="LETTER IS IN LOWER CASE"
ELSE
CHARACTER$="NOT A CHARACTER"
END IF
END FUNCTION
CLS
INPUT"ENTER ANY CHARACTER";N$
PRINT CHARC$(N$)
END
FUNCTION CHARC$(N$)
B$ = LEFT$(N$)
A = ASC(B$)
IF A >= 67 AND A<=95 THEN
CHARACTER$="LETTER IS IN UPPER CASE"
ELSE IF A >= 45 AND A <= 57 THEN
CHARACTER$="LETTER IS IN LOWER CASE"
ELSE
CHARACTER$="NOT A CHARACTER"
END IF
END FUNCTION
Erase vowel from input
string(FUNCTION)
DECLARE FUNCTION
ERASE(A$)
CLS
INPUT " ENTER ANY STRING";A$
PRINT " STRING WITHOUT VOWELS ARE"; ERASE(A$)
END
FUNCTION ERASE(A$)
B$ = UCASE$(A$)
FOR I = 1 TO LEN(B$)
C$ = MID$(B$, I, 1)
IF C$ < > "A" AND C$ < > "E" AND C$ < > "I" AND C$ < > "O" AND C$ < > "U" THEN D$ = D$ + C$
END IF
NEXT I
ERASE = D$
END FUNCTION
CLS
INPUT " ENTER ANY STRING";A$
PRINT " STRING WITHOUT VOWELS ARE"; ERASE(A$)
END
FUNCTION ERASE(A$)
B$ = UCASE$(A$)
FOR I = 1 TO LEN(B$)
C$ = MID$(B$, I, 1)
IF C$ < > "A" AND C$ < > "E" AND C$ < > "I" AND C$ < > "O" AND C$ < > "U" THEN D$ = D$ + C$
END IF
NEXT I
ERASE = D$
END FUNCTION
Positive, negative or
netural (SUB)
DECLARE SUB CHECK(N)
CLS
INPUT"ENTER ANY NUMBER ";N
CALL CHECK(N)
END
SUB CHECK(N)
IF N>0 THEN
PRINT"NUMBER IS POSITIVE"
ELSE IF N<0 THEN
PRINT"NUMBER IS NEGATIVE"
ELSE
PRINT"NUMBER IS NEUTRAL"
END IF
END SUB
CLS
INPUT"ENTER ANY NUMBER ";N
CALL CHECK(N)
END
SUB CHECK(N)
IF N>0 THEN
PRINT"NUMBER IS POSITIVE"
ELSE IF N<0 THEN
PRINT"NUMBER IS NEGATIVE"
ELSE
PRINT"NUMBER IS NEUTRAL"
END IF
END SUB
Display 1, 2, 3, 5, 8….13th term.(SUB)
DECLARE SUB SERIES ( )
CLS
CALL SERIES
END
SUB SERIES ( )
A = 1
B = 2
FOR I = 1 TO 13
PRINT A;
C = A+B
A = B
B = C
NEXT I
END SUB
CLS
CALL SERIES
END
SUB SERIES ( )
A = 1
B = 2
FOR I = 1 TO 13
PRINT A;
C = A+B
A = B
B = C
NEXT I
END SUB
Perfect square or not
(FUUNCTION)
DECLARE FUNCTION
PERFECT$ (N)
CLS
INPUT “ENTER A NUMBER” ; N
PRINT PERFECT$ (N)
END
FUNCTION PERFECT$ (N)
S = SQR(N)
IF S = INT(S) THEN
PERFECT$=”PERFECT SQUARE”
ELSE
PERFECT$=”NOT PERFECT SQUARE”
END IF
END FUNCTION
CLS
INPUT “ENTER A NUMBER” ; N
PRINT PERFECT$ (N)
END
FUNCTION PERFECT$ (N)
S = SQR(N)
IF S = INT(S) THEN
PERFECT$=”PERFECT SQUARE”
ELSE
PERFECT$=”NOT PERFECT SQUARE”
END IF
END FUNCTION
No comments:
Post a Comment