QBASIC

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

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

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

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

  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

You might also like