Saturday, January 21, 2017

Top 10 QB problems & solotions

Some importance QBASIC programs

1) Wap to check whether a number is armstrong or not.

INPUT “NUMBER”;N
A=N
DO
R=N MOD 10
SUM=SUM + r^3
N=N10
LOOP WHILE N>0
IF SUM=A THEN
PRINT “ARMSTRONG”
ELSE
PRINT “NOT ARMSTRONG”
END IF
END

 2) Wap to display reverse form of a input word.

 INPUT “ENTER WORD”;A$
FOR I=LEN(A$) TO 1 STEP -1
B$=MID$(A$,1,I)
C$=C$+B$
NEXT I
PRINT C$

 3. Wap to check whether a number is palindrome of not.

INPUT ‘NUMBER’;N
A=N
DO
R= N MOD 10
SUM=SUM*10+R
N=N10
LOOP WHILE N<>0
IF A=SUM THEN
PRINT “PALINDROME”
ELSE
PRINT “NOT PALINDROME”
END IF
END


4. Wap to print only the vowels for a given word.

CLS
INPUT “ENTER WORD”;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
PRINT C$
END IF
NEXT I
END


5. Wap to ask 2 numbers and find H.C.F. and L.C.M. of given number.

CLS
INPUT A
INPUT B
IF A>B THEN SWAP A,B
FOR I=1 TO A
R= A MOD I
R1= B MOD I
IF R=0 AND R1=0 THEN
H=I
END IF
NEXT I
L=(A*B)/H
PRINT “H.C.F.”;H
PRINT “L.C.M”;L
END


6. Wap to check whether the first character of the word is capital, small or numerical.

CLS
INPUT “ENTER ANY WORD”;N$
A$=LEFT$(N$,1)
A=ASC(A$)
SELECT CASE A
CASE 48 TO 57
PRINT “NUMBER”
CASE 65 TO 90
PRINT “UPPER CASE”
CASE 97 TO 122
PRINT “LOWER CASE”
CASE ELSE
PRINT “IT IS OUT OF RANGE”
END SELECT
END



7. Wap to enter full name and display the initials only.

 CLS
INPUT “ENTER FULL NAME”;N$
C$=LEFT$(N$,1)
FOR I= 1 TO LEN(N$)
IF MID$(N$,I,1) = “ ” THEN
C$=C$ + MID$(N$,I+1,1)
END IF
NEXT I
PRINT “THE INITIALS ARE”;C$
END


8. Wap to convert binary into decimal.
INPUT B
I=0
DO
R= B MOD 10
D= D + R * 2^I
I=I+1
B=B10
LOOP WHILE B<>0
PRINT “DECIMAL”;D
END


9.Wap to convert decimal no. into binary.
CLS
INPUT D
B=2
WHILE  D<>0
R= D MOD B
D=DB
B$=STR$(R) + B$
WEND
PRINT B$


10. Display the sum of the digits of the entered number by the user
CLS
INPUT “enter any number”;N
LET S = 0
TOP:
LET L = N MOD 10
LET S = S + L
LET N = N \ 10
IF N > 0 THEN GOTO TOP
PRINT “the sum of the digits of the number is:”;S
END



No comments:

Post a Comment