0% found this document useful (0 votes)
199 views

Qbasic

This document contains 26 QBASIC programs to calculate areas and volumes of shapes, convert between units, perform mathematical operations, and print patterns and strings. The programs demonstrate the use of basic programming structures like FOR-NEXT loops, WHILE-WEND loops, and SELECT-CASE statements to iterate, make decisions, and output formatted text and numbers.

Uploaded by

mustapha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
199 views

Qbasic

This document contains 26 QBASIC programs to calculate areas and volumes of shapes, convert between units, perform mathematical operations, and print patterns and strings. The programs demonstrate the use of basic programming structures like FOR-NEXT loops, WHILE-WEND loops, and SELECT-CASE statements to iterate, make decisions, and output formatted text and numbers.

Uploaded by

mustapha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Write a program in QBASIC to calculate the area and circumference of a circle of the

radius 14 cm.
(Hint: Area of a circle = 22/7 * r2, Circumference = 2 * 22/7 * r)
Answer
Cls
Let R = 14
Let A = 22 / 7 * R * R
Let C = 2 * 22 / 7 * R
Print "AREA= "; A; "SQ CM"
Print "CIRCUMFERENCE= "; C; "CM"
End
Output
AREA = 616 SQ CM
CIRCUMFERENCE = 88 CM

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

You might also like