Sunteți pe pagina 1din 23

Introduction

QBASIC (Quick Beginners All Purpose Symbolic Instruction Code ) is a


programming language developed by Microsoft . Corporation to use the MS-DOS
operating system. it is the successor of the earlier version of BASIC. it was developed
by John.J Kemeny and Thomas E. Kurtz in 1964 at Dartmouth College, New
Hemisphere. Today many Version of BASIC are available such as BASICA, GW
BASIC, Turbo BASIC, VB , and QBASIC etc.

Features of QBASIC

It is easy to learn and understand.


It is user friendly language.
QBASIC programs are portable
It allows us to test/debug the program.
It supports Structure Programming
It allows function or Procedure to be defined in the program.

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.

SOME SOLVED PROGRAMS

1. Write a program to check Odd or Even numbers.

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

2. WAP to calculate profit or loss in an item

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

3. WAP to check password

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

4.WAP to check input letter is vowel or consonant.

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

7. WAP to check whether an entered word is Palindrom or not.

CLS

INPUT"Enter any Word";A$

FOR I =LEN(A$) TO STEP -1

B$=B$+MID$(A$,I,1)

NEXT I

IF B$=A$ THEN

PRINT"Entered word is Palindrom"

ELSE

PRINT"Enterd word is not Palindrom"

END IF

END

8.WAP to convert the temperature given in Centigrade into Fahrenheit.

CLS

INPUT"Enter temperature in Centigrade";c

f=c*(9/5)+32
PRINT"The temperature in Fahrenheit";f

END

9.WAP to calculate cube root of a given number.

CLS

INPUT"Enter any number";n

c=n^(1/3)

PRINT"Cube root of ";n;"is";c

END

10. WAP to calculate square root of a given number.

CLS

INPUT"Enter any number";n

s=SQR(n)

PRINT"Square root of ";n;"is";s

END

11. WAP to print the greatest among ten different numbers.

CLS

INPUT "Enter first number";g

FOR I = 2 TO 10
INPUT "Enter next number";a

IF a>g THEN g=a

NEXT I

PRINT g ;"is the greatest number"

END

12. WAP to input any number and display whether input number is perfect square or
not.

CLS

INPUT"Enter any number";n

r=SQR(n)

s=INT(r)

IF s= r THEN

PRINT " Perfect Square"

ELSE

PRINT"Not Perfect Square"

END IF

END

13. WAP to check whether input number is perfectly divisible by 5 and 7.

CLS
INPUT "Enter a number "; a

IF a mod 5 = 0 AND a MOD 7 = 0 THEN

PRINT " Entered number is perfectly divisible by 5 and 7 "

ELSE

PRINT " Entered number is not perfectly divisible by 5 and 7"

END IF

END

14.WAP to display the middle number among three given numbers.

CLS

INPUT"Enter the First number"; a

INPUT"Enter the Second number"; b

INPUT"Enter the Third number"; c

IF a > b AND a > c THEN

IF b > c THEN m=b

IF c > b THEN m=c

ELSE IF b > a AND b > c THEN

IF a > c THEN m=a

IF c > a THEN m = c
ELSE

IF b > a THEN m=b

IF a > b THEN m=a

END IF

PRINT " The middle number is :";m

END

15.WAP to input CP and SP and determine whether there is Profit or Loss.

CLS

INPUT "Enter the cost price";CP

INPUT " Enter the selling price ";SP

IF SP > CP THEN

PRINT " Profit is Rs . ";SP-CP

ELSE

PRINT "Loss is Rs.";CP-SP

END IF

END

16. WAP to input day code and display the day name.

17. WAP to display the even number from 50 to 1


CLS

FOR I = 50 TO 1 STEP-2

PRINT I

NEXT I

END

18.WAP to input percentage and display the division.

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

20. WAP to display whether input number is prime or composite

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"

ELSE IF D>2 THEN

PRINT"Composite"

ELSE

PRINT"Neither Prime or Composite"

END IF

END

21. WAP to display the multiplication table of 2 to 9 upto 10th term.

22. WAP to input any number and display whether input number is positive , negative
or neutral.

CLS

INPUT"Enter any number";n


r=SGN(n)

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

INPUT"Enter any number";n

r=SQR(n)

s=INT(r)

IF s=r THEN

PRINT"Perfect square"

ELSE
PRINT"Not Perfect Square"

END IF

END

24.WAP to input any string and dispaly it in reverse order.

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

PRIN"The reverse word =";R$

END

25.WAP to display all the ASCII code with character from 0 to 255.

26. WAP to dispaly square root of first 10 natural numbers.

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$)

IF C$="A" OR C$="E" OR C$="I" OR C$="O" OR C$="U" THEN

PRINT C$

END IF

NEXT I

END

28.WAP to input any sting and display total number of character available in that
string.

CLS

INPUT"Enter any string";A$

L=LEN(A$)

PRINT"Total number of characters are : ";L

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

INPUT "Enter a sentence ";N$

FOR I = 1 TO LEN (N$)

M$=UCASE$(MID$(N$,I,1))

IF M$="R" THEN

C=C+1

NEXT I

PRINT " Total number of alphabet R is ";C

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

INPUT "Enter any string";N$

FOR I =1 TO LEN (N$)


M$= MID$(N$,I,1)

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

INPUT"Enter full name";N$

FOR I = 1 TO LEN(N$)

IF MID$(N$,I,1) = " " THEN

PRINT MID$(N$,P+1,1);"."

P=I : END IF

NEXT I

PRINT RIGHT$ (N$,LEN(N$)-P)


END

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

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 other character"

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

38. WAP to find the sum of individual digits of a numbers.

CLS

INPUT" Enter any number";N

WHILE N<>0

R=N MOD 10

S=S+R
N=N\10

WEND

PRINT " Sum of digit ="; S

END

39.WAP to convert binary to decimal.

CLS

INPUT A

I=0

DO

R = A MOD 10

D= D+R *2^I

I=I+1

A=A/10

LOOP WHILE B<>0

PRINT "Decimal";D

END

40.WAP to convert decimal number to octal number.

CLS

INPUT " Enter decimal number";D


WHILE D<>0

R= D MOD 8

S$ = STR $(R)+S$

D=D\8

WEND

PRINT "Octal equivalent value =";S$

END

41. WAP to convert octal number to decimal number.

CLS

INPUT"Enter octal number";N$

FOR I = LEN(N$) TO 1 STEP -1

B$= MID$ (N$,I,1)

S=S+VAL(B$) * 8^P

P=P+1

NEXT I

PRINT"Decimal equivalent value= ";S

END

42.WAP to convert decimal number to hexadecimal number.


CLS

INPUT"Enter decimal number";D

WHILE D<>0

R=D MOD 16

S$ = STR$(R) +S$

ELSE

S$=CHR$(R+55) +S$

END IF

D=D\16

WEND

PEINT "Hexadecimal equivalent value =";S$

END

43. WAP to convert hexadecimal number to decimal number

CLS

INPUT "Enter hexadecimal number";N$

FOR I= LEN(N$) TO 1 STEP -1

B$=MID$ (N$ ,I ,1)

IF B$ = "A" THEN B$="10"

IF B$ = "B" THEN B$="11"

IF B$ = "C" THEN B$="12"


IF B$ = "D" THEN B$="13"

IF B$ = "E" THEN B$="14"

IF B$ = "F" THEN B$="15"

S=S+VAL (B$) *16^P

P=P+1

NEXT I

PRINT "Decimal equivalent value =";S

END

44. WAP to check given number is Armstrong number or not

CLS

INPUT"Enter a number ";N

S=N

WHILE N<>0

A= N MOD 10

R =R + A^3

N = FIX (N/10)

WEND

IF S=R THEN

PRINT " given number is Armstrong"


ELSE

PRINT " Given number is not Armstrong"

END IF

END

45. WAP to reverse a given number.

CLS

INPUT "Enter a number";N

WHILE N<>0

A = N MOD 10

R = R *10 +A

N = FIX (N/10)

WEND

PRINT R

END

S-ar putea să vă placă și