QBASIC Programs ( Class 6, 7 & 8 )

Write a program for the following.

a. To calculate area of a rectangle.

REM PROGRAM TO DISPLAY AREA OF RECTANGLE

CLS

INPUT “ENTER LENGTH”; L

INPUT “ENTER BREADTH”; B

A = L * B

PRINT “AREA OF RECTANGLE”; A

END

b. To calculate perimeter of a rectangle.

REM PROGRAM TO DISPLAY PERIMETER OF A RECTANGLE

CLS

INPUT “ENTER LENGTH”; L

INPUT “ENTER BREADTH”; B

P=2(l+b)

PRINT “AREA OF RECTANGLE ”; P

END

c. To calculate area of a circle.

REM PROGRAM TO DISPLAY AREA OF CIRCLE

CLS

INPUT “ENTER RADIUS”; R

A = 3.14 * R ^ 2

PRINT “AREA OF CIRCLE ”; A

END

d. To calculate perimeter of a circle.

CLS

REM PROGRAM TO DISPLAY PERIMETER OF A CIRCLE

INPUT” ENTER THE RADIUS ” ;R

LET PERIMETER =22/7*R*2

PRINT ” THE AREA OF CIRCLE =” ;PERIMETER

END

e. To calculate sum of two different numbers.

REM PROGRAM TO DISPLAY SUM OF TWO NUMBERS

CLS

INPUT “ENTER THE FIRST NUMBER”; A

INPUT “ENTER THE SECOND NUMBER”; B

C = A + B

PRINT “SUM OF TWO NUMBERS ”; C

END

F. To calculate product of two different numbers.

REM PROGRAM TO DISPLAY PRODUCT OF TWO NUMBERS

CLS

INPUT “ENTER THE FIRST NUMBER”; A

INPUT “ENTER THE SECOND NUMBER”; B

C = A * B

PRINT “PRODUCT OF TWO NUMBERS ”; C

END

g. To calculate difference of two different numbers.

REM PROGRAM TO DISPLAY DIFFERENCE OF TWO NUMBERS

CLS

INPUT “ENTER THE FIRST NUMBER”; A

INPUT “ENTER THE SECOND NUMBER”; B

C = A – B

PRINT “DIFFERENCE OF TWO NUMBERS ”; C

END

H. To input three different numbers and decide the smallest number amongst the three using IF…THEN statement.

REM program to enter any three numbers and find the smallest number

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

PRINT “FIRST NUMBER IS SMALLEST”;A

ELSEIF B<A AND B<C THEN

PRINT “SECOND NUMBER IS SMALLEST”;B

ELSEIF C<A AND C<B THEN

PRINT “THIRD NUMBER IS SMALLEST”;C

ELSE

PRINT “ALL ARE EQUAL”

ENDIF

END

I . To input days of a week and decide “school day” or “holiday” using IF ….THEN statement.

REM PROGRAM TO ENTER ANY DAY FROM SUNDAY TO SATURDAY AND PRINT “SCHOOL DAY” OR “HOLIDAY”.

CLS

INPUT “ENTER ANY DAY”;DAY$

IF DAY$=”SUNDAY” THEN

PRINT “SCHOOL DAY”

ELSEIF DAY$=”MONDAY” THEN

PRINT “SCHOOL DAY”

ELSEIF DAY$=”TUESDAY” THEN

PRINT “SCHOOL DAY”

ELSEIF DAY$=”WEDNESDAY” THEN

PRINT “SCHOOL DAY”

ELSEIF DAY$=”THURSDAY” THEN

PRINT “SCHOOL DAY”

ELSEIF DAY$=”FRIDAY” THEN

PRINT “SCHOOL DAY”

ELSEIF DAY$=”SATURDAY” THEN

PRINT “HOLIDAY”

ELSE

PRINT “INVALID INPUT”

ENDIF

END

J. To decide whether an input number is divided by 5 and 3 or not?

CLS

INPUT “ENTER THE NUMBER”;N

IF N/5=0 AND N/3=0 THEN

PRINT “DIVISIBLE”

ELSE

PRINT “NOT DIVISIBLE”

END IF

END

k. To input any number from 0 to 9 and check whether it is single digit number or not using SELECT CASE statement.

CLS

INPUT”ENTER THE NUMBER”;N

SELECT CASE N

CASE 0

PRINT “It is single”

CASE 1

PRINT “It is single”

CASE 2

PRINT “It is single”

CASE 3

PRINT “It is single”

CASE 4

PRINT “It is single”

CASE 5

PRINT “It is single”

CASE 6

PRINT “It is single”

CASE 7

PRINT “It is single”

CASE 8

PRINT “It is single”

CASE 9

PRINT “It is single”

CASE ELSE

PRINT “It is not single”

END SELECT

END

l. To input name of the SAARC country and print name of their capital city using SELECT CASE statement.

CLS

INPUT “ENTER THE SAARC COUNTRY NAME”;C$

SELECT CASE C$

CASE “NEPAL”

PRINT “KATHMANDU”

CASE “AFGANISTAN”

PRINT “KABUL”

CASE “INDIA”

PRINT “DELHI”

CASE “PAKISTAN”

PRINT ISLAMABAAD

CASE “BANGLADESH”

PRINT “DHAKA”

CASE “BHUTAN”

PRINT “THIMPU”

CASE “MALDIVES”

PRINT “MALE”

CASE “SRI LANKA”

PRINT “COLOMBO”

CASE ELSE

PRINT “ERROR”

END SELECT

END

3. WAP to perform the following using library function.

a. Write a program to return MAN form the word KATHMANDU.

CLS

C$=”KATHMANDU”

PRINT MID$(C$,5,3)

END

b. Write a program to return NEP form the word NEPAL.

CLS

C$=”NEPAL”

PRINT LEFT$(C$,3)

END

c. Write a program to return PAL form the word NEPAL.

CLS

C$=”NEPAL”

PRINT RIGHT$(C$,3)

END

d. Write a program to return ASCII value of letter ‘a’.

CLS

PRINT ASC(“a”)

END

f. Write a program to return RETUPMOC form the word COMPUTER.

REM PROGRAM TO REVERSE A STRING

CLS

C$=”COMPUTER”

FOR J=8 TO 1 STEP -1

M$=MID$(C$,J,1)

REV$=REV$+M$

NEXT J

PRINT “REVERSED STRING IS “;REV$

END

1) Write a program to enter your name and print it .

CLS

Input ‘Enter your name’;n$

Print ‘The name is’;n$

End

2) Write a program to enter your name, city, country, age and print them.

CLS

Input ” Enter the name “;N$

Input ” Enter the city”;C$

Input ” Enter the country”;CO$

Input ” Enter the age”;A

Print ” The name is “;N$

Print ” The city is “;C$

Print ” The country is “;CO$

Print ” The age is “;A

End

3) Write a program to find the area of the triangle.

Cls

Input ” enter the base” ;b

Input ” enter the height” ;h

let T = 1/2*b*h

Print” The area of triangle=” ;T

End

4) Write a program to find the area of the square.

Cls

Input” Enter the number” ;n

Let square= n^2

Print” The area of square=” ;Square

End

5) Write a program to find the area of the square and cube.

Cls

Input” Enter the number” ;n

Let square= n^2

Let Cube = n^3

Print” The area of square=” ;Square

Print” The area of cube=” ; Cube

End

6) Write a program to find the volume of the box.

Cls

Input ” enter the length ” ;l

Input ” enter the breadth ” ;b

Input ” enter the height ” ;h

Let Volume= l*b*h

Print” The volume of box =” ;Volume

End

7) Write a program to convert the weight from kilogram to pounds.

CLS

Input”Enter the weight in kilogram”;K

Let P=K*2.2

Print “The pound is “;P

End

8) Write a program to convert the distance from kilometer to miles.

Cls

Input”Enter the length in kilometer”;K

Let M= K / 1.6

Print “The length in miles =”;M

End

9)Write a program to convert the distance from miles to kilomiles.

Cls

Input ” Enter the length in miles”;M

Let K=M*1.6

Print” The length in kilo miles=”;K

End

10) Write a program to enter the initial mileage(m1) and final mileage (m2) then calculate the distance traveled.

CLS

Input “Enter the Initial Mileage”;M1

Input “Enter the Final Mileage”;M2

Let D= M2-M1

Print ” The distance covered=”;D

End

11) Write a program to find out the simple Interest and the Amount.

Cls

Input ” Enter the Principal”;P

Input ” Enter the Rate”;R

Input ” Enter the Time”;T

Let I = P*T*R/100

Let A= P + I

Print ” The simple Interest = “;I

Print ” The amount=”;A

End

12) Write any number and find it’s half.

Cls

Input “Enter the desired number “; N

Let H = N/2

Print “The half of the number = “;H

END

13) Write a program to find the area of four walls of a room.

Cls

Input”Enter the height “;H

Input”Enter the length “; L

Input”Enter the Breadth”;B

Let A= 2 * H * (L+B)

Print ” The area of four walls =”;A

End

14) Write a program to enter any three numbers, sum and the average.

Cls

Input ” Enter any number” ;A

Input ” Enter any number” ;B

Input ” Enter any number” ;C

Let Sum = A+B+C

Let Average =Sum/3

Print” The sum=” ;Sum

Print” The Average is ” ;Average

End

15) Write a program to enter any two numbers their Sum, Product and the Difference.

CLS

Input ” Enter any number” ;A

Input ” Enter any number” ;B

Let Sum = A+B

Let Difference= A-B

Let Product = A*B

Print” the sum =” ;Sum

Print” the Difference =” ;Difference

Print” the Product =” ; Product

End

16) Write a program to input student’s name, marks obtained in four different subjects, find the total and average marks.

Cls

Input” Enter the name ” ;N$

Input” Enter the marks in English” ;E

Input” Enter the marks in Maths” ;M

Input” Enter the marks in Science” ;S

Input” Enter the marks in Nepali” ;N

Let S=E+M+S+N

Let A=S/4

Print ” The name of the student is” ;N$

Print ” The total marks is” ;S

Print ” The Average marks” ;A

End

17) Write a program to find 10%,20% and 30% of the input number.

Cls

Input” Enter any number” ;N

Let T=10/100*N

Let Twe=20/100*N

Let Thi=30/100*N

Print ” 10%of input number=” ;T

Print ” 20%of input number=” ;Twe

Print ” 30%of input number=” ;Thi

End

18) Write a program to convert the distance to kilometer to miles.

Cls

Input” Enter the kilometer” ;K

Let M=K/1.6

Print ” The miles = ” ;M

End

19) Write a program to find the perimeter of square.

Cls

Input “Enter the length”; L

Let P =4 * L

Print “ The perimeter of square=”;P

End

20) Write a program to enter the Nepalese currency and covert it to Indian Currency.

CLS

Input “Enter the Nepalese currency” ;N

Let I = N * 1.6

Print “the Indian currency=”;I

End

21) Write a program to enter the Indian currency and covert it to Nepalese Currency.

CLS

Input “Enter the Indian currency” ;N

Let N = I / 1.6

Print “the Nepalese currency=”;I

End

22) Write a program to enter any number and find out whether it is negative or positive.

CLS

Input “Enter the number”; N

If N>0 Then

Print “ The number is positive”

Else

Print “The number is negative”

EndIf

End

23) Write a program to enter any number and find out whether it is even or odd using select case statement.

Cls

Input “Enter any number” ;N

R=N mod 2

Select case R

Case = 0

Print “The number is Even number”

Case Else

Print “The number is odd number”

End Select

End

24) Write a program to check the numbers between 1 & 3.

Cls

Input “Enter the numbers between 1-3”;N

Select case N

Case 1

Print “It’s number 1”;

Case 2

Print “It’s a number 2”;

Case 3

Print “It’s a number 3”

Case else

Print “It’s out of range”;

End select

End

25) Write a program to enter any alphabet and test alphabet is ‘a’ or not using the select case statement.

Cls

Input “Enter the alphabet”;A$

A$=UCase$ (A$)

Select Case A$

Case ‘A’

Print “It’s alphabet A”

Case Else

Print “It’s not alphabet A”

End Select

End

26) Write a program to enter any alphabet and find out whether the number is vowel or alphabet.

Cls

Input “Enter Letters/Alphabet”;A$

A$ = UCase $ (A$)

Select case A$

Case “A”, “E”, “I”, “O”, “U”

Print “Its’ a vowel”

Case Else

Print “ It’s not a vowel”

End Select

End

Looping

To print multiplication table of INPUT number. [FOR…NEXT]

CLS

INPUT “Enter any number:”;n

FOR i=1 TO 10

PRINT N; ” X ” ;  i  ;  ” = ” ; n * i

NEXT i

END

a)     To print multiplication table of 7. (7×1=7) [FOR…NEXT]

CLS

FOR i=1 TO 10

PRINT 7; ” X ” ;  i  ;  ” = ” ; 7 * i

NEXT i

END

b)      To print your mother name 15 times. [While….Wend]

CLS

c=1

while c<=15

print “Manisha”

c=c+1

wend

end

c)      To print numbers from 15 to 1. [For…NEXT]

CLS

For i = 15 to 1 Step -1

Print i

Next i

End

d)    To print sum of odd numbers between 2 and 20. [WHILE….WEND]

CLS

i=2

while i<=20

print i

i=i+2

wend

end

e)      To print the series 1, 8, 27, upto 10th terms.

CLS

for i=1 to 10

print i^3

next i

end

f)       To print the series 1, 2, 3, 5, 8, ………. upto 10th terms.

CLS

A = 1

B = 1

PRINT A; B;

FOR i = 1 TO 10

C = A + B

PRINT C;

A = B

B = C

NEXT

END

g)      To print the following output:

                                i.            5, 10, 15……upto 50

CLS

i=5

while i<=50

print i

i=i+5

wend

end

                             ii.            70, 65, 60………upto 10

CLS

For i = 70 to 10 Step -5

Print i

Next i

End

                          iii.            5, 55, 555 upto 5th terms.

cls

num=5

for i=1 to 5

print num;

num=num*10+5

next i

end

h)     Write a program to print the following output of “NEPAL”.

CLS    

s$=”NEPAL”

FOR I = 1 TO LEN(S$)

PRINT LEFT$(S$, I)

NEXT I

End

i) Write a program to print input string into reverse order.

CLS

INPUT “ENTER THE TEXT”;A$

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

B$=MID$(A$,i,1)

C$=C$+B$

NEXT i

PRINT”THE REVERSE IS:”;C$

END

********************************************

Thanks for support. If you like this content please comment.

One thought on “QBASIC Programs ( Class 6, 7 & 8 )

Leave a Reply

Your email address will not be published. Required fields are marked *