QBASIC
• Stands for Quick Beginners’ All purpose Symbolic Instruction Code.
• High Level Programming Language.
• Developed by Microsoft in 1985.
• Smart Editor automatically formats the line.
• View window is used to write QBASIC programs.
• Immediate window is used to change single statement ,formula, etc.
• Also has feature of cut-paste and copy-paste.
• Totally algorithmic Programming.
Basic Examples:
1.WAP to find the sum of two numbers.
CLS
INPUT “ENTER ANY TWO NUMBERS”;A,B
S= A+B
PRINT “THE SUM OF TWO NUMBERS IS”;S
END
2.WAP to find the difference of two numbers.
CLS
INPUT “ENTER ANY TWO NUMBERS”;A,B
D= A-B
PRINT “THE DIFFERENCE OF TWO NUMBERS IS”;D
END
3.WAP to find the product of two numbers.
CLS
INPUT “ENTER ANY TWO NUMBERS”;A,B
P= A*B
PRINT “THE PRODUCT OF TWO NUMBERS IS”;P
END
4.WAP to find the area of rectangle.
CLS
INPUT “ENTER LENGTH AND BREADTH”;L,B
A = L*B
PRINT “THE AREA OF RECTANGLE IS”;A
END
5.WAP to find the area of circle.
CLS
INPUT “ENTER RADIUS”;R
A = (22/7)*R^2
PRINT “THE AREA OF CIRLCE IS”;A
END
6.WAP to calculate the perimeter of rectangle. P = 2(L+B)
CLS
INPUT “ENTER LENGTH AND BREADTH”;L,B
P = 2*(L+B)
PRINT “THE PERIMETER OF RECTANGLE IS”;P
END
7.WAP to calculate the circumference of a circle. C = 2ЛR
CLS
INPUT “ENTER RADIUS OF CIRLCE”;R
C = 2*(22/7)*R
PRINT “THE CIRCUMFERENCE OF CIRCLE IS”;C
END
8.WAP to find the volume of cube. V= L3
CLS
INPUT “ENTER LENGTH”;L
V = L^3
PRINT “THE VOLUME OF CUBE IS”;V
END
9.WAP to find the simple interest. ( I = PTR/100)
CLS
INPUT “ENTER PRINCIPAL”;P
INPUT “ENTER TIME”;T
INPUT “ENTER RATE”;R
I = (P*T*R)/100
PRINT “THE SIMPLE INTEREST IS”;I
END
Try it yourself
FIND RATE IF PRINCIPAL, TIME AND INTEREST IS GIVEN
FIND TIME IF PRINCIPAL, TIME AND INTEREST IS GIVEN
10.WAP to accept the degree in Celsius and convert it into Fahrenheit scale where F = (9/5) x C + 32
CLS
INPUT “ENTER DEGREE IN CELSIUS”;C
F = (9/5)*C+32
PRINT “THE VALUE IN FAHRENHEIT IS”;F
END
11.WAP to find the square root of any number.
INPUT “ENTER A NUMBER”;N
P = SQR(N)
PRINT “THE SQAURE ROOT OF NUMBER IS”; P
END
12.WAP to check whether the given number is positive or negative.
INPUT “ENTER A NUMBER”;N
IF N > 0 THEN
PRINT “ IT IS POSITIVE”
ELSE
PRINT “IT IS NEGATIVE”
END IF
END
13.WAP to check whether the given number is even or odd.
INPUT “ENTER A NUMBER”;N
IF N MOD 2 = 0 THEN
PRINT “IT IS EVEN NUMBER”
ELSE
PRINT “IT IS ODD NUMBER”
END IF
END
14.WAP to print the largest number among two numbers.
INPUT “ENTER A FIRST NUMBER”;A
INPUT “ENTER A SECOND NUMBER”;B
IF A > B THEN
PRINT “ THE LARGEST NUMBER IS”;A
ELSE
PRINT “THE LARGESR NUMBER IS”;B
END IF
END
15.WAP to print the largest number among three numbers.
INPUT “ENTER THREE NUMBERS”; A, B, C
IF A>B AND A >C THEN
PRINT “THE LARGEST NUMBER IS”; A
ELSEIF B> A AND B>C THEN
PRINT “THE LARGEST NUMBER IS”;B
ELSE
PRINT “THE LARGEST NUMBER IS”;C
END IF
END
TRY YOURSELF: WAP TO PRINT THE SMALLEST NUMBER AMONG THREE NUMBERS.
16.WAP to check whether the given number is perfect square or not.
INPUT “ENTER A NUMBER”;N
P = SQR(N)
IF P = INT(P)
PRINT “IT IS PERFECT SQUARE”
ELSE
PRINT “IT IS NOT PERFECT SQUARE”
END IF
END
17.WAP to print the first 10 natural numbers.
CLS
FOR I= 1 TO 10
PRINT I
NEXT I
END
18.WAP to print first 20 even numbers.
CLS
A=2
FOR I= 1 TO 20
PRINT A;
A=A+2
NEXT I
END
TRY YOURSELF: WAP TO PRINT THE FIRST 20 ODD NUMBERS.
19.WAP to print the multiplication table of a given number.
CLS
INPUT “ENTER A NUMBER”;N
FOR I = 1 TO 10
P = N* I
PRINT P
END
No comments:
Post a Comment