Wednesday 26 September 2018

Qbasic for SEE 2075


QBASIC PROGRAMS For SEE
Set -1
1. Write a program to calculate the volume of a cylinder using FUNCTION……END FUNCTION. [Hint:  PI*R^2*H]
Ans:
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 

2. Write a program to test whether the given number is positive or negative using SUB……END SUB.
Ans:
DECLARE SUBTEST(N)
CLS
INPUT “Enter a number”; N
CALL TEST(N)
END
SUB TEST(N)
IF N>0 THEN
PRINT N; “is positive number”
ELSE
PRINT N; “is negative number”
END IF
END SUB


3.  Write a program to print the following series: 1,4,7,……. up to 10th term using FUNCTION……END FUNCTION.
ANS :
 DECLARE FUNCTION SERIES
CLS
D= SERIES
END
FUNCTION SERIES
FOR I = 1 TO 10
PRINT A;
A=A+3
NEXT I
END FUNCTION


4.  Write a program which accepts any three different numbers and find the maximum number among them using CALL statement.

Ans:
 DECLARE SUB MAX(A,B,C)
CLS
INPUT “Enter any three number’; A,B,C
CALL MAX(A,B,C)
END
SUB MAX(A,B,C)
IF A>B AND A>C THEN
PRINT A; “is maximum number”
ELSEIF B>A AND B>C THEN
PRINT B; “is maximum number”
ELSE
PRINT C; “is maximum number”
END IF
END SUB

5.  Write a program to display greater number among any two numbers using FUNCTION……. END FUNCTION.
ANS :
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


6Write a program to print the following series: 1, 8, 27, 64,  …….. up to 10th terms using SUB procedure

Ans
DECLARE SUB SERIES()
CLS
CALL SERIES
END
SUB SERIES
FOR I =  1 TO 10
PRINT I^3;
NEXT I
END SUB


7. Write a program to find the factorial number of any non-negative number using FUNCTION…… END FUNCTION.
Ans:
 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


8. Write a program to display the series 55555, 5555, 555, 55, 5 using SUB………END SUB.
Ans:
DECLARE SUB SERIES()
CLS
CALL SERIES
END
SUB SERIES
A#= 55555
FOR I = 1TO 5
PRINT A#;
A#=A#\10
NEXT I
END SUB


9.  Write a program to display vowels and consonants of the entered string by using FUNCTION …….. END FUNCTION.
Ans:
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






10.Write a program to display the reverse of the entered number by using SUB….. END SUB.
Ans:
DECLARE SUB REV(N)
CLS
INPUT “Enter a number”; N
CALL REV(N)
END
SUB REV(N)
S=0
WHILE N<>0
R=N MOD 10
S=S*10+R
N=N\10
WEND
PRINT “The reversed form=”;S
END SUB

11.   Write a program to declare a user defined function to return a given number in reverse order by using FUNCTION…… END FUNCTION.
Ans:
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
12 Write a program to declare a SUB procedure module to generate multiplication table of any non-negative number, where number is passed as a parameter by using SUB….. END SUB statement.
Ans:
DECLARE SUB MUL(N)
CLS
INPUT “Enter a number”; N
CALL MUL(N)
END
SUB MUL(N)
FOR I = 1 TO 10
PRINT N; “*”;I; “=”; N*I
NEXT I
END SUB


13. Write a program to define a function procedure to display area of sphere where user has to input the required data in the main module. [Hint: Area of sphere: 4*PI*R^2]
Ans
DECLARE FUNTION AREA(R)
CLS
CONST PI= 3.14
INPUT “Enter radius”; R
PRINT “The area of sphere=”; AREA(R)
END
FUNCTION AREA(R)
A=4*PI*R^2
AREA=A
END FUNCTION
14.Write a program to define SUB procedure to display the following series of number: 1, 1, 2, 3, 5, …..up to 13thterm.
Ans:
 DECLARE SUB SERIES()
CLS
CALL SERIES
END
SUB SERIES
A=1
B=1
PRINT A;B;
FOR I =1 TO 11
C=A+B
PRINT C;
A=A+B
B=A+B
NEXT I
END SUB

15. Using user defined function, write a program to input monthly income in parameter then computer annual tax to be paid. The tax rate is 15% if annual income is above Rs. 200000, otherwise tax rate is 1%.
Ans
DECLARE FUNCTION TAX(I)
CLS
INPUT “Enter monthly income”; I
PRINT “Tax to be paid=”; TAX(I)
END
FUNCTION TAX(I)
A=I*12
IF A>200000 THEN
TAX=15/100*A
ELSE
TAX=1/100*A
END IF
END FUNCTION

16. Write a program to generate the series using SUB …… END SUB : -10, -8, -6, -4, ………. Up to 20th term.
Ans
DECLARE SUB SERIES()
CLS
CALL SERIES
END
SUB SERIES
A=-10
FOR I = 1 TO 20
PRINT A;
A=A+2
NEXT I
END SUB
17. Write a program using FUNCTION….END FUNCTION to calculate and print the total surface area of a sphere.
Ans
DECLARE FUNCTION TSA(R)
CLS
CONST PI=3.14
INPUT “Enter radius”; R
PRINT “The total surfacearea of sphere=”; TSA(R)
END
FUNCTION TSA(R)
T= 4*PI*R^2
TSA=T
END FUNCTION

18. Write a program to declare Sub procedure to print only the vowels from a given word.
Ans:
DECLARE SUB VOW(S$)
CLS
INPUT “Enter a word”; S$
CALL VOW(S$)
END
SUB 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 SUB
19.  Write a program that asks any number and calculates its factors using a SUB procedure.

Ans
DECLARE SUB FACT(N)
CLS
INPUT “Enter a number”; N
CALL FACT(N)
END
SUB FACT(N)
PRINT “The factors of”; N; “are”
FOR I = 1 TO N
IF N MOD I = 0 THEN PRINT I
NEXT I
END SUB









20. Write a program that asks any three numbers and displays the difference between the greatest and the smallest value among the 3 supplied numbers using FUNCTION procedure.
Ans:
DECLARE FUNCTION DIF(A,B,C)
CLS
INPUT “Enter three numbers”; A, B, C
PRINT “THE DIFFERENCE=”; DIF(A, B, C)
END
FUNCTION DIF (A, B, C)
G = 0
S = 0
IF A > B AND A > B THEN
G = A
ELSEIF B > A AND B > C THEN
G = B
ELSE
G = C
END IF
IF A < B AND A < C THEN
S = A
ELSEIF B < A AND B < C THEN
S = B
ELSE
S = C
END IF
DIF = G – S
END FUNCTION
































QBASIC PROGRAMS For SEE
Set -2

1. WRITE A PROGRAM TO FIND AREA OF FOUR WALLS.
Using Function Procedure: 
DECLARE FUNCTION AREA(L,B,H)
CLS
INPUT “ENTER LENGTH” ; L
INPUT “ENTER BREADTH” ; B
INPUT “ENTER HEIGHT” ; H
PRINT “THE AREA OF FOUR WALLS= ” ; AREA(L,B,H)
END
FUNCTION AREA(L,B,H)
AREA=2*H*(L+B)
END FUNCTION
Using SUB Procedure
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 IS “; A
END FUNCTION

2. Write a program to define a function procedure that returns simple interest.
Using FUNCTION Procedure : 
DECLARE FUNCTION SI(P,T,R)
CLS
INPUT “ENTER PRINCIPLE” ; P
INPUT “ENTER TIME” ; T
INPUT “ENTER RATE” ; R
PRINT “SIMPLE INTEREST IS = ” ;SI(P,T,R)
END
FUNCTION SI(P,T,R)
SI=(P*T*R)/100
END FUNCTION
Using SUB Procedure :
DECLARE SUB SI(P,T,R)
CLS
INPUT “ENTER PRINCIPLE” ; P
INPUT “ENTER TIME” ; T
INPUT “ENTER RATE” ; R
CALL SI(P,T,R)
END
SUB SI(P,T,R)
I=(P*T*R)/100
PRINT “INTEREST IS ” ; I
END SUB
3. Write a program to convert the supplied Nepalese currency into its equivalent Indian currency.

Using FUNCTION Procedure :
DECLARE FUNCTION CONV(N)
CLS
INPUT “ENTER NEPALESE CURRENCY ” ; P
PRINT “INDIAN CURRRENCY = ” ;CONV(P)
END
FUNCTION CONV(P)
CONV=P/1.6
END FUNCTION
Using SUB Procedure:
DECLARE SUB CONV(N)
CLS
INPUT “ENTER NEPALESE CURRENCY ” ; P
CALL CONV(P)
END
SUB CONV(P)
C=P/1.6
PRINT “INDIAN CURRENCY “; C
END SUB
4. Write a program  to check whether an input number is even or odd.
Using Function Procedure:
DECLARE FUNCTION CONV$(N)
CLS
INPUT “ENTER  A NUMBER ” ; P
PRINT CONV$(P)
END
FUNCTION CONV$(P)
IF P MOD 2 = 0 THEN
CONV$=”EVEN NUMBER”
ELSE
CONV$=”ODD NUMBER”
ENDIF
END FUNCTION
Using SUB Procedure:
DECLARE SUB CONV(P)
CLS
INPUT “ENTER  A NUMBER ” ; P
CALL CONV(P)
END
SUB CONV(P)
IF P MOD 2 = 0 THEN
PRINT “EVEN NUMBER”
ELSE
PRINT “ODD NUMBER”
ENDIF
END SUB

5. Write a program to check whether the input number is divisible by 4 and  6  or not.
Using Function Procedure:
DECLARE FUNCTION CHECK$(N)
CLS
INPUT “ENTER  A NUMBER ” ; P
PRINT CHECK$(P)
END
FUNCTION CHECK$(P)
IF P MOD 4 =0 AND P MOD 6=0 THEN
CHECK$=”DIVISIBLE BY BOTH NUMBERS”
ELSE
CONV$=”NOT DIVISIBLE BY BOTH NUMBERS”
ENDIF
END FUNCTION
Using Sub Procedure: 
DECLARE SUB CHECK(N)
CLS
INPUT “ENTER  A NUMBER ” ; P
CALL  CHECK(P)
END
SUB CHECK(P)
IF P MOD 4 =0 AND P MOD 6=0 THEN
PRINT “DIVISIBLE BY BOTH NUMBERS”
ELSE
PRINT “NOT DIVISIBLE BY BOTH NUMBERS”
ENDIF
END SUB
6. Write a program  to calculate the square of all digits of input number.
Using Function Procedure:
DECLARE FUNCTION SQU(A)
CLS
INPUT “ENTER A NUMBER” ; N
PRINT SQU(N)
FUNCTION SQU(N)
WHILE N<>0
R=N MOD 10
S=R^2
PRINT   S
N=N\10
WEND
END DUNCTION
Using Sub Procedure :
DECLARE SUB SQU(A)
CLS
INPUT “ENTER A NUMBER” ; N
CALL SQU(N)
END
SUB SQU(N)
WHILE N<>0
R=N MOD 10
S=R^2
PRINT   S
N=N\10
WEND
END SUB
7. Write a program to calculate the circumference of circle.
Using Function Procedure:
DECLARE FUNCTION CIR(A)
CLS
INPUT “ENTER RADIUS OF A CIRCLE”; R
PRINT “CIRCUMFERENCE IS” ; CIR(R)
END
FUNCTION CIR(A)
P=3.14
CIR=2*P*A
END FUNCTION
Using SUB Procedure:
DECLARE SUB CIR(A)
CLS
INPUT “ENTER RADIUS OF A CIRCLE”; R
CALL CIR(R)
END
SUB CIR(A)
P=3.14
C=2*P*A
PRINT “CIRCUMFERENCE IS ” ; C
END SUB
8. Write a program to display the reverse of input string .
Using Function Procedure
DECLARE FUNCTION REV$(N$)
CLS
INPUT “ENTER A STRING” ; W$
PRINT  “REVERSED STRING::”;REV$(W$)
END
FUNCTION REV$(N$)
FOR I = LEN(N$) TO 1 STEP -1
D$=D$+MID$(N$,I,1)
NEXT I
REV$=D$
END FUNCTION
Using SUB Procedure:
DECLARE SUB REV(N$)
CLS
INPUT “ENTER A WORD” ; W$
CALL REV(W$)
END
SUB REV(N$)
FOR I = LEN(N$) TO 1 STEP-1
C$=C$+MID$(N$,I,1)
NEXT I
PRINT “REVERSED STRING” ; C$
END SUB
9. Write a program that accepts three different numbers and returns the smallest one.
Using Function Procedure:
DECLARE FUNCTION SMALL(A,B,C)
CLS
INPUT “ENTER FIRST NUBER” ; A
INPUT “ENTER SECOND NUMBER” ; B
INPUT “ENTER THIRD NUMBER” ; C
PRINT “THE SMALLEST NUMBER IS” ; SMALL(A,B,C)
FUNCTION SMALL(A,B,C)
IF A<B AND B<C THEN
SMALL=A
ELSE IF B<A AND A<C THEN 
SMALL=B
ELSE
SMALL=C
END FUNCTION
Using SUB Procedure:
DECLARE SUB SMALL(A,B,C)
CLS
INPUT “ENTER FIRST NUBER” ; A
INPUT “ENTER SECOND NUMBER” ; B
INPUT “ENTER THIRD NUMBER” ; C
CALL SMALL(A,B,C)
FUNCTION SMALL(A,B,C)
IF A<B AND B<C THEN
PRINT “SMALLEST” ; A
ELSE IF B<A AND A<C THEN
PRINT “SMALLEST” ; B
ELSE
PRINT “SMALLEST” ; C
END SUB
10. WAP to find whether the first character of the input string is a number, an uppercase or lowercase character or none of them.

Using Function Procedure:
DECLARE FUNCTION CHTR$(A$)
CLS
INPUT “ENTER A STRING” ; C$
PRINT CHTR$(C$)
END
FUNCTION CHTR$(A$)
D$=LEFT$(A$)
A=ASC(D$)
IF A>=65 AND A<=90 THEN
CHTR$=”FIRST LETTERIS UPPERCASE LETTER”
ELSEIF A>=97 AND A<=122 THEN
CHTR$=”FIRST LETTER IS LOWERCASE”
ELSEIF A>=48 AND A<=57 THEN
CHTR$=”FIRST LETTER IS NUMBER”
ELSE
CHTR$=”NONE OF THEM”
END FUNCTION
Using SUB Procedure:
DECLARE SUB CHTR(A$)
CLS
INPUT “ENTER A STRING” ; C$
CALL CHTR(C$)
END
SUB CHTR(A$)
D$=LEFT$(A$)
A=ASC(D$)
IF A>=65 AND A<=90 THEN
PRINT “FIRST LETTER IS UPPERCASE LETTER”
ELSEIF A>=97 AND A<=122 THEN
PRINT “FIRST LETTER IS LOWERCASE”
ELSEIF A>=48 AND A<=57 THEN
PRINT “FIRST LETTER IS NUMBER”
ELSE
PRINT “NONE OF THEM”
END SUB



























QBASIC PROGRAMS SET-3 [SUB AND FUNCTION]

1. Write a program to display the reverse of input string .
Using Function Procedure.

DECLARE FUNCTION REV$(N$)
CLS
INPUT “ENTER A STRING” ; W$
PRINT  “REVERSED STRING::”;REV$(W$)
END
FUNCTION REV$(N$)
FOR I = LEN(N$) TO 1 STEP -1
D$=D$+MID$(N$,I,1)
NEXT I
REV$=D$
END FUNCTION

Using SUB Procedure
DECLARE SUB REV(N$)
CLS
INPUT “ENTER A WORD” ; W$
CALL REV(W$)
END
SUB REV(N$)
FOR I = LEN(N$) TO 1 STEP-1
C$=C$+MID$(N$,I,1)
NEXT I
PRINT “REVERSED STRING” ; C$
END SUB
2. write a program to check whether the entered number is prime or composite.
using sub procedure

DECLARE SUB PRIME (N)
INPUT “ENTER ANY NUMBER”; N
CALL PRIME (N)
END

SUB PRIME (N)
C = 0
FOR I = 1 TO N
IF N MOD I = 0 THEN C = C + 1
NEXT I
IF C = 2 THEN
PRINT N; “IS PRIME NUMBER”
ELSE
PRINT N; “IS COMPOSITE NUMBER”
END IF
END SUB

Using function procedure

DECLARE FUNCTION PRIME(N)
CLS
INPUT “ENTER ANY NUMBER”; N
P = PRIME (N)
IF P = 2 THEN
PRINT N; “IS PRIME NUMBER”
ELSE
PRINT N; “IS COMPOSITE NUMBER”
END IF
END

FUNCTION PRIME (N)
C = 0
FOR I = 1 TO N
IF N MOD I = 0 THEN C = C + 1
NEXT I
PRIME = C
END FUNCTION

3.write a program to check input number is Armstrong or not?
USING SUB PROCEDURE
DECLARE SUB ARM (N)
CLS
INPUT “ENTER ANY NUMBER”; N
CALL ARM (N)
END

SUB ARM (N)
A = N
S = 0
WHILE N < > 0
R = N MOD 10
S = S  + R ^ 3
N = N \ 10
WEND
IF A = S THEN
PRINT A; “IS ARMSTRONG NUMBER”
ELSE
PRINT A; “IS NOT ARMSTRONG NUMBER”
END IF
END SUB

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

4.write a program to find the area of square.
USING SUB PROCEDURE

DECLARE SUB AREA (L)
CLS
INPUT “ENTER LENGTH”; L
CALL AREA(L)
END

SUB AREA (L)
A = L ^ 2
PRINT “AREA OF SQUARE”; A
END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION AREA (L)
CLS
INPUT “ENTER LENGTH”; L
AR = AREA(L)
PRINT “AREA OF SQUARE ”; AR
END

FUNCTION AREA (L)
A = L ^ 2
AREA = A
END FUNCTION

5.write a program to input a string and count the total numbers of vowels.

USING SUB PROCEDURE
DECLARE SUB COUNT (S$)
CLS
INPUT “ENTER ANY STRING”; S$
CALL COUNT(S$)
END

SUB COUNT (S$)
VC = 0
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
VC = VC + 1
END IF
NEXT I
PRINT “TOTAL NO. OF VOWELS= “; VC
END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION COUNT (S$)
CLS
INPUT “ENTER ANY STRING”; S$
PRINT “TOTAL NO. OF VOWELS= “; COUNT(S$)
END

FUNCTION COUNT (S$)
VC = 0
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
VC = VC + 1
END IF
NEXT I
COUNT = VC
END FUNCTION

6.write a program to input a string and display only vowels.
 USING SUB PROCEDURE
DECLARE SUB DISPV (S$)
CLS
INPUT “ENTER ANY STRING”; S$
CALL DISPV(S$)
END

SUB DISPV(S$)
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$
END IF
NEXT I
END SUB



USING FUNCTION PROCEDURE

DECLARE FUNCTION DISPV (S$)
CLS
INPUT “ENTER ANY STRING”; S$
VC = DISPV(S$)
END

FUNCTION DISPV(S$)
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$
END IF
NEXT I
END FUNCTION

7.write a program to input string and display only consonants.

USING SUB PROCEDURE

DECLARE SUB DISPC (S$)
CLS
INPUT “ENTER ANY STRING”; S$
CALL DISPC(S$)
END

SUB DISPC(S$)
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” AND C$ <> ” ” AND C$ <> “.” THEN
PRINT B$
END IF
NEXT I
END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION DISPC (S$)
CLS
INPUT “ENTER ANY STRING”; S$
CC = DISPC(S$)
END

FUNCTION DISPC(S$)
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” AND C$ <> ” ” AND C$ <> “.” THEN
PRINT B$
END IF
NEXT I
END FUNCTION

8. write a program to check whether the input number is positive, negative or zero.

USING SUB PROCEDURE

DECLARE SUB CHECK (N)
CLS
INPUT “ENTER ANY NUMBER”; N
CALL CHECK (N)
END
SUB CHECK (N)
IF N > 0 THEN
PRINT N; IS POSITIVE NUMBER”
ELSEIF N < 0 THEN
PRINT N; IS NEGATIVE NUMBER”
ELSE
PRINT N; IS ZERO”
END IF
END SUB

USING FUNCTION PROCEDURE

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

9.write a program to print string in alternate capita .eg.CoMpUtEr

USING SUB PROCEDURE

DECLARE SUB ALTERNATE (A$)
INPUT “ENTER STRING”; 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 “THE REQUIRED ALTERNATE IS” ;ALT$
END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION ALTERNATE$ (A$)
CLS
INPUT “ENTER STING”; A$
PRINT “THE REQUIRED ALTERNATE IS”; ALTERNATE$ (A$)
END

FUNCTION ALTERNATE$ (A$)
FOR I = 1 TO LEM (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


10.write a program that prints the sum of even digits.

USING SUB PROCEDURE

DECLARE SUB SUMEVEN (N)
CLS
INPUT “ENTER ANY NUMBER”; N
CALL SUMEVEN (N)
END

SUB SUMEVEN (N)
S = 0
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 0 THEN S = S + R
N = N \ 10
WEND
PRINT “SUM OF EVEN DIGITS”; S
END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION SUMEVEN (N)
CLS
INPUT “ENTER ANY NUMBER”; N
SU = SUMEVEN (N)
PRINT “SUM OF EVEN DIGITS”; SU
END

FUNCTION SUMEVEN (N)
S = 0
WHILE N < > 0
R = N MOD 10
IF R MOD 2 = 0 THEN S = S + R
N = N \ 10
WEND
SUMEVEN = S
END FUNCTION

11.write a program to convert the temperature given in the centigrade to farenhiet. (9C +160/5)

USING SUB PROCEDURE

DECLARE SUB CONVERT (C)
CLS
INPUT “ENTER TEMPERATURE IN CELCIUS”; C
CALL CONVERT (C)
END

SUB CONVERT (C)
F = C * (9 / 5) + 160
PRINT “TEMPERATURE IN FARENHEIT=”; F
END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION CONVERT (C)
CLS
INPUT “ENTER TEMPERATURE IN CELSIUS”; C
PRINT “TEMPERATURE IN FAHRENHEIT=”; CONVERT (C)
END

FUNCTION CONVERT (C)
F = C * (9 / 5) + 160
CONVERT = F
END FUNCTION


12.write a program to find the perimeter of the rectangle.2(l+b)

USING SUB PROCEDURE

DECLARE SUB PERIMETER (L, B)
CLS
INPUT “ENTER LENGTH”; L
INPUT “ENTER BREADTH”; B
CALL PERIMETER(L, B)
END

SUB PERIMETER (L, B)
P = 2 * (L + B)
PRINT “PERIMETER OF RECTANGLE ”; P
END SUB

USING FUNCTION PROCEDURE

DECLARE FUNCTION PERIMETER (L, B)
CLS
INPUT “ENTER LENGTH”; L
INPUT “ENTER BREADTH”; B
PR = PERIMETER(L, B)
PRINT “PERIMETER OF RECTANGLE ”; PR
END

FUNCTION PERIMETER (L, B)
P = 2 * (L + B)
PERIMETER = P
END FUNCTION


QBASIC PROGRAMS FOR SEE [SUB AND FUNCTION PROCEDURE] (SET 4)

1. Write  a program to check whether a supplied number is perfect square or not ?
Using SUB Procedure:
DECLARE SUB PRSQR(N)
CLS
INPUT “ENTER A NUMBER” ; N
CALL PRSQR(N)
END
SUB PRSQR(N)
S=SQR(N)
IF S = INT(S) THEN
PRINT “SUPPLIED NUMBER IS PERFECT SQUARE”
ELSE
PRINT “SUPPLIED NUMBER IS NOT PERFECT SQUARE”
ENDIF
END SUB
USING FUNCTION PROCEDURE 
DECLARE FUNCTION PRSQR$(N)
CLS
INPUT “ENTER A NUMBER” ; N
PRINT PRSQR$(N)
END
FUNCTION PRSQR$(N)
S=SQR(N)
IF S = INT(S) THEN
PRSQR$=”PERFECT SQUARE”
ELSE
PRSQR$=”NOT PERFECT SQUARE”
ENDIF
END SUB
2. Write a program to display the sum of individual digits of multi digit input number.
Using Sub Procedure
DECLARE SUB SUMDIG(N)
CLS
INPUT “ENTER MULTIGIT NUMBER” ; N
CALL SUMDIG(N)
END
SUB SUMDIG(N)
WHILE N<>0
R=N MOD 10
S=S+R
N=N\10
WEND
PRINT “SUM IS ” ; S
END SUB
Using Function Procedure:
DECLARE FUNCTION SDIG(N)
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
3. Write a program to count the total words present in an input string.
USING SUB PROCEDURE
DECLARE SUB WCOUNT(N$)
CLS
INPUT “ENTER A STRING” ; N$
CALL WCOUNT(N$)
END
SUB WCOUNT(N$)
C=1
FOR I = 1 TO LEN(N$)
C$=MID$(N$,I,1)
IF C$=” ” THEN C=C+1
NEXT I
PRINT “NUMBER OF C” ; C
END SUB

4. Write a program to print the longest string among three different supplied string.
Using SUB Procedure
DECLARE SUB LON(A$,B$,C$)
CLS
INPUT “ENTER FIRST STRING ” ; A$
INPUT “ENTER SECOND” ; S$
INPUT “ENTER THIRD” ; T$
CALL LON(A$,S$,T$)
END
SUB LON(A$,B$,C$)
A=LEN(A$)
B=LEN(B$)
C=LEN(C$)
IF A>B AND A>C THEN
LONG$=A$
ELSEIF B>A AND B>C THEN
LONG$=B$
ELSE
LONG$=C$
ENDIF
PRINT “LONGEST STRING” ; LONG$
END SUB
USING FUNCTION
DECLARE FUNCTION LONG$(A$,B$,C$)
CLS
INPUT “ENTER FIRST STRING ” ; A$
INPUT “ENTER SECOND” ; S$
INPUT “ENTER THIRD” ; T$
PRINT “LONGEST STRING” ;  LONG$(A$,S$,T$)
END
FUNCTION LONG$(A$,B$,C$)
A=LEN(A$)
B=LEN(B$)
C=LEN(C$)
IF A>B AND A>C THEN
LONG$=A$
ELSEIF B>A AND B>C THEN
LONG$=B$
ELSE
LONG$=C$
ENDIF
END FUNCTION
5. Write a program to find the factors of input number
DECLARE SUB FACT(N)
CLS
INPUT “ENTER A NUMBER”; N
CALL FACT(N)
END
SUB FACT(N)
FOR I = 1 TO N
IF N MOD I = 0 THEN PRINT I;
NEXT I
END SUB
6. Write a program to find the sum of factors of input number.
DECLARE SUB FACT(N)
CLS
INPUT “ENTER A NUMBER”; N
CALL FACT(N)
END
SUB FACT(N)
FOR I = 1 TO N
IF N MOD I = 0 THEN  S=S+I
NEXT I
PRINT “SUM OF FACTORS” ; S
END SUB
7. Check input number is prime or not.
CLS
DECLARE SUB PRIME(A)
CLS
INPUT “ENTER A NUMBER” ; N
CALL PRIME(N)
END
SUB PRIME(A)
FOR I = 1 TO A
IF A MOD I = 0 THEN C=C+1
NEXT I
IF C=2 THEN
PRINT “PRIME”
ELSE
PRINT “NOT PRIME
ENDIF
END SUB
8. Write a program to display Armstrong numbers from 1 to 500
DECLARE SUB ARM
CLS
CALL ARM
END
SUB ARM
FOR I = 1 TO 500
A=I
S=0
WHILE A<>0
R=N MOD 10
S=S+R^3
A=A\10
WEND
IF S=I THEN
PRINT “ARMSTRONG”
ELSE
PRINT “NOT ARMSTRONG”
ENDIF
END SUB
9. Display palindrome numbers from 1 to 1000
DECLARE SUB PAL()
CLS
CALL PAL
END
SUB PAL
FOR I = 1 TO 1000
A=I
S=0
WHILE A<>0
R=N MOD 10
S=S*10+R
A=A\10
WEND
IF S=I THEN
PRINT “PALINDROME”
ELSE
PRINT “NOT PALINDROME”
ENDIF
END SUB
10. Display prime numbers from 1 to 500
DECLARE SUB PRIME()
CLS
CALL PRIME
END
SUB PRIME
FOR I = 1 TO 500
C=0
FOR J = 1 TO I
IF I MOD J=0 THEN C=C+1
NEXT J
IF C=2 THEN PRINT I;
NEXT I
END SUB




Some Program
1. Display initial letters.
Using Sub Procedure :
DECLARE SUB INI(S$)
CLS
INPUT “ENTER YOUR FULL NAME “; F$
CALL INI(F$)
END
SUB INI(S$)
P$=” “+S$ ‘ ADDS SPACE BEFORE STRING
FOR I = 1 TO LEN(S$)
A$=MID$(P$,I,1)
B$=MID$(S$,I,1)
IF A$=” ” THEN C$=C$+B$
NEXT I
PRINT “YOUR NAME IN SHORT FORM : ” ; C$
END SUB
Using Function :
DECLARE FUNCTION INI$(S$)
CLS
INPUT “ENTER YOUR FULL NAME “; F$
PRINT INI$(F$)
END
FUNCTION INI$(S$)
P$=” “+S$ 
FOR I = 1 TO LEN(S$)
A$=MID$(P$,I,1)
B$=MID$(S$,I,1)
IF A$=” ” THEN C$=C$+B$
NEXT I
INI$=C$
END FUNCTION
2. COUNT TOTAL NUMBERS OF WORD
Using Sub Procedure :
DECLARE SUB COUNT(S$)
CLS
INPUT “ENTER YOUR FULL NAME “; F$
CALL COUNT(F$)
END
SUB COUNT(S$)
C=1
FOR I = 1 TO LEN(S$)
B$=MID$(S$,I,1)
IF B$=” ” THEN C=C+1
NEXT I
PRINT “TOTAL WORDS : ” ; C
END SUB
Using Function :
DECLARE FUNCTION COUNT(S$)
CLS
INPUT “ENTER YOUR FULL NAME “; F$
PRINT COUNT(F$)
END
FUNCTION COUNT(S$)
C=1
FOR I = 1 TO LEN(S$)
A$=MID$(S$,I,1)
IF A$=” ” THEN C=C+1
NEXT I
COUNT=C
END FUNCTION

Prepared By:_ Ramesh Mahato
Email:- mahatoramesh873@gmail.com
website:- rameshworld.com
Phone Number:-9854038468



No comments:

Post a Comment

MCQ Question Bank Microsoft PowerPoint