QBASIC Programming
1. Using function procedure WAP to check whether the given number is Armstrong or not.
Ans: DECLARE FUNCTION CHECK$(N)
CLS
PRINT ''DOLKAR''
PRINT
INPUT''ENTER ANY NUMBER'';N
PRINT ''THE GIVEN NUMBER IS '';CHECK$(N)
END
FUNCTION CHECK$(N)
A=N
WHILE N< >0
R=N MOD 10
S=S+R^3
N=N\10
WEND
IF A=S THEN
CHECK$=''ARMSTRONG''
ELSE
CHECK$=''NOT ARMSTRONG''
END IF
END FUNCTION
2. Using sub procedure WAP to check whether the given number is palindrome or not.
Ans: DECLARE SUB CHECK(N)
CLS
PRINT ''DOLKAR''
PRINT
INPUT ''ENTER ANY NUMBER'';N
CALL CHECK(N)
END
SUB CHECK(N)
A=N
WHILE N< >0
R=N MOD 10
S=S*10+R
N=N\10
WEND
IF A=S THEN
PRINT ''THE GIVEN NUMBER IS PALINDROME''
ELSE
PRINT ''THE GIVEN NUMBER IS NOT PALINDROME''
END IF
END SUB
3. Using sub procedure WAP to display the factors of a given number.
Ans: DECLARE SUB FACTOR(N)
CLS
PRINT ''DOLKAR''
PRINT
INPUT ''ENTER ANY NUMBER'';N
CALL FACTOR(N)
END
SUB FACTOR(N)
FOR I= 1 TO N
IF N MOD I=0 THEN PRINT I
NEXT I
END SUB
4. Using function procedure WAP to display the factorial of a given number.
Ans: DECLARE FUNCTION FACT(N)
CLS
PRINT ''DOLKAR''
PRINT
INPUT ''ENTER ANY NUMBER'';N
PRINT ''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
5. Using sub procedure WAP to reverse the given digit.
Ans: DECLARE SUB REV(N)
CLS
PRINT ''DOLKAR''
PRINT
INPUT ''ENTER ANY NUMBER'';N
CALL REV(N)
END
SUB REV(N)
WHILE N< >0
R=N MOD 10
S=S*10+R
N=N\10
WEND
PRINT ''REVERSED DIGIT='';S
END SUB
6. Using function procedure WAP to check whether the given number is prime or composite.
Ans: DECLARE FUNCTION CHECK$(N)
CLS
PRINT ''DOLKAR''
PRINT
INPUT''ENTER ANY NUMBER'';N
PRINT ''THE GIVEN NUMBER IS '';CHECK$(N)
END
FUNCTION CHECK$(N)
FOR I= 1 TO N
IF N MOD I=0 THEN C=C+1
NEXT I
IF C=2 THEN
CHECK$=''PRIME''
ELSE
CHECK$=''COMPOSITE''
END IF
END FUNCTION
7. Using sub procedure WAP to find the sum of given digits.
Ans: DECLARE SUB SUM(N)
CLS
PRINT ''DOLKAR''
PRINT
INPUT ''ENTER ANY NUMBER'';N
CALL SUM(N)
END
SUB SUM(N)
WHILE N< >0
R= N MOD 10
S=S+R
N =N\10
WEND
PRINT ''THE SUM OF GIVEN DIGITS IS '';S
END SUB
8. Using function procedure WAP to count total number of odd digits in a given number.
Ans: DECLARE FUNCTION COUNT(N)
CLS
PRINT ''DOLKAR''
PRINT
INPUT ''ENTER ANY NUMBER'';N
PRINT ''TOTAL NUMBER OF ODD DIGITS IS ''; COUNT(N)
END
FUNCTION COUNT(N)
WHILE N< >0
R= N MOD 10
IF R MOD 2 = 1 THEN S=S+R
N =N\10
WEND
COUNT = S
END FUNCTION
9. Using sub procedure WAP to display only even numbers from the input digit.
Ans: DECLARE SUB DIS(N)
CLS
PRINT ''DOLKAR''
PRINT
INPUT ''ENTER ANY NUMBER'';N
CALL DIS(N)
END
SUB DIS(N)
PRINT ''THE EVEN DIGITS ARE''
WHILE N< >0
R= N MOD 10
IF R MOD 2 = 0 THEN PRINT R
N =N\10
WEND
END SUB
10. Using function procedure WAP to find the H.C.F and L.C.M of a given number.
Ans: DECLARE FUNCTION HCF(A,B)
DECLARE FUNCTION LCM(A,B)
DECLARE FUNCTION LCM(A,B)
CLS
PRINT ''DOLKAR''
PRINT
INPUT ''ENTER ANY TWO NUMBERS''; A ,B
PRINT ''H.C.F.='' ;HCF(A,B)
PRINT ''L.C.M.='' ;LCM(A,B)
END
FUNCTION HCF(A,B)
FOR I = 1 TO A
IF A MOD I = 0 AND B MOD I = 0 THEN
HCF=I
END IF
NEXT I
FOR I = 1 TO A
IF A MOD I = 0 AND B MOD I = 0 THEN
HCF=I
END IF
NEXT I
END FUNCTION
FUNCTION LCM(A,B)
FOR I = 1 TO A
IF A MOD I = 0 AND B MOD I = 0 THEN H=I
NEXT I
L=A*B/H
LCM=L END FUNCTION
IF A MOD I = 0 AND B MOD I = 0 THEN H=I
NEXT I
L=A*B/H
LCM=L END FUNCTION
Comments
Post a Comment