Académique Documents
Professionnel Documents
Culture Documents
Features of QBASIC
Loading QBASIC
The QBASIC program consist two files- QBASIC.EXE and QBASIC.HLP. To load
QBASIC program on your computer you need to run QBASIC.EXE file in the
memory.
Elements of QBASIC
The elements of QBASIC are the building blocks of any programs in QBASIC. The
elements of QBASIC are required to construct the program in QBASIC. Following
are the elements of QBAISC:
Character Sets
QBASIC words
Variables
Constants
Operators
Expression
Character Set
QBASIC contains three sets of characters. The characters set include alphabet,
number and special characters. All the characters other than the alphabetical and
numeric are called special characters.
QBASIC words:
The words used in QBASIC is called QBASIC words.Following are the two types of
QBASIC words.
Reserved Words(Keywords)
User defined words.
CLS
INPUT "Enter the number";n
IF n MOD 2 =0 THEN
PRINT "The number is Even"
ELSE
PRINT" The number id Odd"
END IF
END
CLS
INPUT"Enter the name of item";name$
INPUT "Enter the cost price";cp
INPUT"Enter the Selling price";sp
IF sp>cp THEN
PRINT " Your Profit is Rs. ";sp-cp
ELSE
PRINT " Your Loss is Rs. ";cp-sp
END IF
END
CLS
INPUT "Enter your password";w$
IF w$="admin"OR w$="ADMIN" THEN
PRINT"Correct"
ELSE
PRINT"Did you forget your Password"
END IF
END
CLS
INPUT"Enter a letter in lower case";ch$
IF ch$ ="a" OR ch$ ="e" OR ch$="i" OR ch$="o" OR ch$="u" THEN
PRINT "Vowel"
ELSE
PRINT"Consonant"
END IF
END
5. WAP to calculate the Simple intrest and the program also prompt to the user to
calculate more.
CLS
INPUT"Enter Principal Amount";P
INPUT"Enter Rate";R
INPUT"Enter number of years";N
I=(P*T*R)/100
PRINT I
INPUT"Any more Calculation?(Y/N)";ch$
IF ch$="Y" OR ch$"="y" THEN GOTO start
END
6. WAP to find the HCF and LCM of any two entered numbers .
CLS
A:
INPUT"Enter first number";x
INPUT"Enter second number";y
IF x<y THEN GOTO A
C=x:D=y
B:
R=x MOD y
IF R= 0 THEN
HCF =y
LCM =(C*D)/HCF
PRINT"HCF is";HCF
PRINT "LCM" is";LCM
ELSE
x=y, y= R
GOTO B
END IF
END
CLS
B$=B$+MID$(A$,I,1)
NEXT I
IF B$=A$ THEN
ELSE
END IF
END
CLS
f=c*(9/5)+32
PRINT"The temperature in Fahrenheit";f
END
CLS
c=n^(1/3)
END
CLS
s=SQR(n)
END
CLS
FOR I = 2 TO 10
INPUT "Enter next number";a
NEXT I
END
12. WAP to input any number and display whether input number is perfect square or
not.
CLS
r=SQR(n)
s=INT(r)
IF s= r THEN
ELSE
END IF
END
CLS
INPUT "Enter a number "; a
ELSE
END IF
END
CLS
IF c > a THEN m = c
ELSE
END IF
END
CLS
IF SP > CP THEN
ELSE
END IF
END
16. WAP to input day code and display the day name.
FOR I = 50 TO 1 STEP-2
PRINT I
NEXT I
END
19. WAP to input any number and display the multiplication table of that number.
CLS
c=1
INPUT"Enter a number";A
WHILE c<=10
T=c*A
PRINT c"x"A"="T
WEND
END
CLS
INPUT"Enter any number";N
FOR I = 1 TO N
IF N MOD I =0 THEN
D=D+1
END IF
NEXT I
IF D=2 THEN
PRINT"Prime"
PRINT"Composite"
ELSE
END IF
END
22. WAP to input any number and display whether input number is positive , negative
or neutral.
CLS
SELECT CASE r
CASE 1
PRINT"Positive Number"
CASE -1
PRINT"Negavtive Number"
CASE 0
PRINT"Neutral Number"
CASE ELSE
PRINT"Invalid Number"
END SELECT
23. WAP to input any number and display whether input number is perfect square or
not.
CLS
r=SQR(n)
s=INT(r)
IF s=r THEN
PRINT"Perfect square"
ELSE
PRINT"Not Perfect Square"
END IF
END
CLS
INPUT"Enter a word";w$
l=LEN(w$)
FOR I = L to 1 STEP -1
A$ =MID$(w$,I,1)
R$=R$+A$
NEXT I
END
25.WAP to display all the ASCII code with character from 0 to 255.
27. WAP to input any string and display all the vowel letter from the string.
CLS
INPUT"Enter word";A$
FOR I = 1 TO LEN(A$)
B$ = MID$(A$,I,1)
C$= UCASE$(B$)
PRINT C$
END IF
NEXT I
END
28.WAP to input any sting and display total number of character available in that
string.
CLS
L=LEN(A$)
END
29. WAP to input any string and count total number of vowel and consonants letters
available in that sting.
30. WAP to input any string and display total number of words available in that
stings.
31. WAP to input any sting and display how many "R" characters are available in that
sting.
CLS
M$=UCASE$(MID$(N$,I,1))
IF M$="R" THEN
C=C+1
NEXT I
END
32. WAP to input any three sting and display greatest string among them.
33. WAP to print the letters one in Uppercase and next in Lowercase. eg .DhAnGaDhI
CLS
IF I MOD 2 =0 THEN
K$= LCASE$(M$)
ELSE
K$=UCASE$(M$)
END IF
L$=L$+K$
NEXT I
PRINT L$
END
34. WAP to input your full name and print initial letters,
CLS
FOR I = 1 TO LEN(N$)
PRINT MID$(N$,P+1,1);"."
P=I : END IF
NEXT I
35. WAP to input any sting and display total number of characters and words
available in that string.
36. WAP to input any string and display whether input sting is number, character in
lowercase, character in uppercase or other characters.
CLS
A$=LEFT$(N$,1)
A=ASC(A$)
SELECT CASE A
CASE 48 TO 57
PRINT" Number"
CASE 65 TO 90
CASE 97 TO 122
CASE ELSE
END SELECT
END
37. WAP to display Hailstone Series. ie 7 , 22 , 11 , 34 ,17 .....upto 10th term
CLS
X=
FOR I = 1 TO 10
PRINT X;
IF X MOD 2 = 0 THEN
X=X/2
ELSE
X=3*X+1
END IF
NEXT I
END
CLS
WHILE N<>0
R=N MOD 10
S=S+R
N=N\10
WEND
END
CLS
INPUT A
I=0
DO
R = A MOD 10
D= D+R *2^I
I=I+1
A=A/10
PRINT "Decimal";D
END
CLS
R= D MOD 8
S$ = STR $(R)+S$
D=D\8
WEND
END
CLS
S=S+VAL(B$) * 8^P
P=P+1
NEXT I
END
WHILE D<>0
R=D MOD 16
S$ = STR$(R) +S$
ELSE
S$=CHR$(R+55) +S$
END IF
D=D\16
WEND
END
CLS
P=P+1
NEXT I
END
CLS
S=N
WHILE N<>0
A= N MOD 10
R =R + A^3
N = FIX (N/10)
WEND
IF S=R THEN
END IF
END
CLS
WHILE N<>0
A = N MOD 10
R = R *10 +A
N = FIX (N/10)
WEND
PRINT R
END