Friday, May 10, 2013

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 ask n numbers and display them in ascending order.

INPUT “ENTER TOTAL NUMBER”;N
DIM ARR(N)
CLS
FOR I= 1 TO N
INPUT “ENTER NUMBER”;ARR(I)
NEXT I
FOR I= 1 TO N-1
FOR J=I+1 TO N
IF ARR(I) > ARR(J) THEN SWAP ARR(I), ARR(J)
NEXT J
NEXT I
FOR I=1 TO N
PRINT ARR(I)
NEXT I
END


8. 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 INTITALS ARE”;C$
END


9.Wap to convert time in seconds into exact hours, minutes and seconds
CLS
INPUT “ENTER THE TIME IN SECONDS”;SC
H=SC/3600
MS=SC MOD 3600
M=MS/60
S= MS MOD 60
PRINT H;”:”;M “:”;S
END


10. 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


11.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$


12. Wap to  find factorial number.
CLS
INPUT “ENTER NUMBER”;N
F=1
WHILE N>=1
F=F*N
N=N-1
WEND
PRINT “FACTORIAL”;F
END


13. Wap to find ab without using the exponent sign(^)
CLS
INPUT A
INPUT B
C=A
FOR I=2 TO B
A=A*C
NEXT I
PRINT A
END


14. Wap to input name and show in ascending order.
CLS
INPUT “HOW MANY NAMES”;N
DIM ARRAY$(N)
FOR I=1 TO N
INPUT “ENTER NAME”;ARRAY$(I)
NEXT I
C=N-1
FLAG=1
DO WHILE FLAG=1
FLAG=0
FOR I=1 TO C
IF ARRAY$(I)>ARRAY$(I+1) THEN
SWAP ARRAY$(I),ARRAY$(I+1)
FLAG=1
END IF
NEXT I
C=C-1
LOOP
PRINT “THE NAMES SORTED ARE:”
PRINT
FOR I=1 TO N
PRINT I; “:”; ARRAY$(I)
NEXT I
END


1. Display the number of characters in the word entered by the user
CLS
INPUT “enter your desired word”;N$
PRINT LEN(N$)
END

2. Display the entered word by the user in a “right angled triangle” form
CLS
INPUT “enter a word”;W$
FOR I = 1 to LEN(W$)
PRINT LEFT$(W$, I)
NEXT I
END

3. Display any word entered by the user in reverse
CLS
INPUT “enter a word”;W$
LET A = LEN(W$)
FOR I = 1 to A
A = A – 1
PRINT MID$(W$, A , 1)
NEXT I


4. Display the entered word (s) in abbreviated form (esp. full name)
CLS
INPUT “enter your full name”;N$
PRINT LEFT$(N$, 1)
FOR I = 2 to LEN(N$)
LET X$ = MID$(N$, I , 1)
IF X$ = “ ” THEN PRINT MID$(N$, I + 1, 1); “.”;
NEXT I
END
5. Display the entered word in reverse form as well as in a decreasing order from left (inverted right angled triangle + reverse word)
CLS
INPUT “enter the desired word”;A$
FOR I = LEN(A$) to 1 STEP-1
FOR X = I to 1 STEP-1
PRINT MID$(A$, X , 1);
NEXT X
PRINT
NEXT I
END

6. Display the entered word in vertical order
CLS
INPUT “enter a word”;W$
FOR A = 1 to LEN(W$)
PRINT MID$(W$, A , 1)
NEXT A
END

7. Display first and last character of any word entered by the user
CLS
INPUT “enter any word”;W$
PRINT LEFT$(W$, 1)
PRINT RIGHT$(W$, 1)
END

8. 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

9. Display a colorful "I LOVE YOU" message
CLS
SCREEN 13
LOCATE 14, 25
PRINT "Cool, Isn't It?"
LOCATE 22, 1
PRINT "-Truly Yours"

I:
PSET (10, 10)
PSET (70, 10)
PSET (10, 90)
PSET (70, 90)

icenter:
PSET (40, 10)
PSET (40, 90)

LINE.i:

LINE (10, 10)-(70, 10), 5'horizontal top
LINE (10, 90)-(70, 90), 5'horizontal bottom
LINE (40, 10)-(40, 90), 5'verticaL

L:
LINE (110, 10)-(110, 60), 6
LINE (110, 60)-(140, 60), 6

CIRCLE (170, 25), 20, 2
V:
LINE (200, 10)-(215, 60), 9
LINE (215, 60)-(230, 10), 9

E:
LINE (245, 10)-(275, 10), 11
LINE (245, 10)-(245, 60), 12
LINE (245, 35)-(265, 35), 12
LINE (245, 60)-(275, 60), 11

YOU:

LINE (80, 110)-(100, 140), 3
LINE (100, 140)-(120, 110), 3
LINE (100, 140)-(100, 180), 4

O:
LINE (150, 110)-(135, 140), 8
LINE (135, 140)-(150, 180), 8
LINE (150, 180)-(170, 140), 8
LINE (170, 140)-(150, 110), 8

U:
LINE (180, 120)-(180, 175), 14
LINE (180, 175)-(185, 180), 14
LINE (185, 180)-(220, 180), 14
LINE (220, 180)-(225, 175), 14
LINE (225, 175)-(225, 120), 14

END

10. Display user's details with music playing
CLS
DEFSTR A, H, N
DEFLNG C-E 'deflng c to e
INPUT "enter your name"; N
INPUT "enter your date of birth"; D
INPUT "enter your address"; A
INPUT "enter your age"; e
INPUT "enter your class"; C
INPUT "enter your hobby"; h
PLAY "a b"
PRINT
PRINT "You will be getting your details in a few seconds"
PLAY " a b c a a d e"
PRINT
PRINT
PRINT "Name: "; N
PRINT "Date of Birth :"; D
PRINT "Address: "; A
PRINT "Age :"; e
PRINT "Class :"; C
PRINT "Hobby :"; h
PRINT
PRINT "THANK YOU!"
PLAY "a b c a a a a b"


END

No comments:

Post a Comment