0% found this document useful (0 votes)
8 views11 pages

Q Basic Programs

The document contains a series of QBasic programming exercises covering various topics such as arithmetic operations, decision control structures, loops, and string manipulation. Each section includes specific tasks like calculating sums, averages, swapping variables, and determining triangle types, along with examples of code to accomplish these tasks. The exercises are designed to help learners practice and understand fundamental programming concepts in QBasic.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views11 pages

Q Basic Programs

The document contains a series of QBasic programming exercises covering various topics such as arithmetic operations, decision control structures, loops, and string manipulation. Each section includes specific tasks like calculating sums, averages, swapping variables, and determining triangle types, along with examples of code to accomplish these tasks. The exercises are designed to help learners practice and understand fundamental programming concepts in QBasic.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

[Link] a program to calculate the sum of three numeric values.

CLS
INPUT "enter the first number"; x
INPUT " enter the second number"; y
INPUT " enter the third number"; z
sum = x + y + z
PRINT "sum is"; sum
END
[Link] find the average of four subject marks.
CLS
INPUT "enter the first subject marks"; x
INPUT " enter the second subject marks"; y
INPUT " enter the third subject marks"; z
INPUT "enter the fourth ubject marks"; p
sum = x + y + z + p
average = sum / 4
PRINT "the average is "; average
END
[Link] read two numbers and swap them using a third temporary
variable.
CLS
INPUT "enter the value of the first variable"; a
INPUT " enter the value ofthe the second Variable"; b
PRINT "the original values ofa and b are"; a, b
c=a
a=b
b=c
PRINT "the swapped values of a and b are "; a, b
END
Q4. [Link] read two numbers and swap them without using a third
temporary variable.
CLS
INPUT "enter the value of the first variable"; a
INPUT " enter the value ofthe the second Variable"; b
PRINT "the original values ofa and b are"; a, b
a=a+b
b=a-b
a=a-b
PRINT "the swapped values of a and b are "; a, b
END
[Link] in Qbasic to find area of a rectangle ,square and circle.
CLS
INPUT "enter the length of rectangle"; l
INPUT " enter the breadth of a rectangle"; b
INPUT "enter the sides of a square"; s
area_of_rect = l * b
area_of_square = s * s
PRINT " the area of a rectangle is "; area_of_rect
PRINT " the area of a square is"; area_of_square
END
[Link] in Qbasic to find out the volume sphere, cylinder and
cone. [Hint: Volume of sphere- 4/3π3, cylinder- 3.14*r*r*h, cone-
1/3π r*r*h]
Q7. WAP in Qbasic to find out the simple interest and amount for
entered principle, rate and time.
CLS
INPUT "enter the principal "; p
INPUT "enter the time"; t
INPUT "enter the rate"; r
simple_interest = (p * r * t) / 100
amount = simple_interest + p
PRINT " the simple interest is"; simple_interest
PRINT "the amount is"; amount
END
DECISION –CONTROL PROGRAM
( IF…..THEN…ELSE, IF…..THEN….ELSEIF)
Q1. WAP to accept two unequal numbers and display the greater of
the two numbers.
CLS
INPUT "enter the first number"; a
INPUT " enter the second number"; b
IF (a <> b) THEN
IF (a > b) THEN
PRINT "the first number is greater than the second"; a
ELSE
PRINT "the second number is greater than the first"; b
END IF
END IF

END
[Link] to accept two numbers and if two numbers are equal then find
the sum otherwise, their product.
CLS
INPUT "enter the first number"; x
INPUT "enter the second number"; y
IF (x = y) THEN
sum = x + y
PRINT " the sum of the two numbers"; sum
ELSE
product = x * y
PRINT " the product of the two numbers"; product
END IF
END

Q3. Wap to enter the two angles and check whether it is complementary ,
supplementary or neither.
CLS
INPUT "enter the first angle"; x
INPUT "enter the second angle"; y
IF (x + y = 90) THEN

PRINT " the angles are complementary"


ELSE IF (x + y = 180) THEN

PRINT " the angles are supplementary"


END IF

END IF
END

Q4. Wap to accept the cost price and selling price of an article.
Calculate the profit percent and the loss percent.
CLS
INPUT "enter the cost_price"; cp
INPUT " enter the selling price"; sp
IF (sp > cp) THEN
profit = sp - cp
PRINT profit, profit_per
ELSE
loss = cp - sp
loss_percent = loss / cp * 100
PRINT loss, loss_percent
END IF
End

Q5. Write a program in Qbasic to input 3 sides of a triangle


and check whether triangle is possible or not. If possible,
then check whether it is an ‘equilateral Triangle’, isosceles
triangle or a scalene triangle.

CLS
INPUT "enter the three sides of a triangle"; a, b, c
IF (a + b > c) AND (b + c > a) AND (c + b > a) THEN
PRINT " Triangle is possible"
IF (a = b) AND (b = c) THEN
PRINT "equilateral triagle"
ELSEIF (a = b) OR (b = c) OR (c = a) THEN
PRINT (" isoscles triangle");
ELSEIF (a <> b) AND (b <> c) AND (c <> a) THEN
PRINT "scalene triangle"
END IF
ELSE
PRINT ("triangle is not possible");
END IF
END

Q6. ‘Bazaar kolkata’ has announced festival discounts on the


purchase of items based on the total cost of the items.
Total cost Discount
Upto rs 2000 5%
Rs 2001- rs 3000 10%
Rs 5001 -10,000 15%
Above rs 10000 20%
Wap in qbasic to input the total cost. Compute and display
the amount to be paid by the customer after discount.
CLS
INPUT "enter the cost of the articl"; p
IF p <= 2000 THEN d = 5 / 100 * p
IF p >= 2001 AND p <= 5000 THEN d = 10 / 100 * p
IF p >= 5001 AND p <= 10000 THEN d = 15 / 100 * p
IF p > 10000 THEN

d = 20 / 100 * p
END IF
PRINT " discount="; d
PRINT "amount is"; p - d
END

Q7 Write a program in qbasic to enter the name and marks


obtained by a student in ‘ computer Project’. Display the
grade as per the table given below:
Marks obtained Grade
80% or more A
60% or more but less than B
80%
40% or more but less than C
60%
Less than 40% No grade

ITERATION OR LOOPS
Q1. To print the natural numbers from 1 to 15
CLS
FOR i = 1 TO 15 STEP 1
PRINT i
NEXT i
END
Q2. To print even numbers from 0 to 20
CLS
FOR i = 0 TO 20 STEP 2
PRINT i
NEXT i
END
Q3. To print numbers from 12 to 1 in descending order
CLS
FOR i = 12 TO 1 STEP -1
PRINT i
NEXT i
END
Q4. TO print the multiplication table upto 12 of the given
number.
CLS
REM " to print the multiplication table of a number"
INPUT "enter the number"; num
FOR i = 1 TO 12 STEP 1
PRINT num; "*"; i; "="; num * i
NEXT i
END
Q5. To accept a 3 digit number and print the sum of the first
and second number and product of the first and last number
CLS
REM " accept a 3 digit number and print the sum of the first
and second and product of the first and last number""
INPUT "enter a 3 digit number"; num
LET first_num = INT(num / 100)
LET last_num = num MOD 10
LET middle_num = INT(num MOD 100) / 10
PRINT first_num, last_num, middle_num
sum = first_num + middle_num
product = first_num * last_num
PRINT sum, product
END

[Link] print the number in reverse order


CLS
REM " accept a 2 digit number and print the sum of the first
and second and product of the first and last number""
INPUT "enter a 2 digit number"; num
LET first_num = INT(num / 10)
LET last_num = num MOD 10
reVERSE = last_num * 10 + first_num
PRINT reVERSE
END
Q7. To accept any range of m and n and print all the odd
numbers between them
CLS
REM " accept a range of m and n and print all odd numbers
between them"
INPUT "enter the value of m"; m
INPUT "enter the value of n"; n
FOR i = m TO n STEP 1
IF (i MOD 2 = 1) THEN
PRINT i
END IF
NEXT i
END
Q8. To accept any number between 100 to 500 and check if it
is even or odd
CLS
REM "ACCEPT NUMBERS FROM 100 TO 500 and check
whether the number is even or odd"

FOR i = 100 TO 500 STEP 1


INPUT "enter the number"; n
IF (n MOD 2 = 0) THEN
PRINT "the number is even"; n
ELSE
PRINT "the number is odd"; n
END IF
NEXT i
END
[Link] to accept a number and find out the factorial of the
number
CLS
REM to find the factorial of a number
Let fact=1
input “enter a number”;n
for i =1 to n step 1
fact=fact*i
next i
print “the factorial of a number”;fact
end

Q10. Wap to accept a number and find out the factors of the
number.
CLS
REM to find the factors of a number
input “enter a number”;n
for i =1 to n step 1
if(n mod i=0) then
print i
next i
print “the factors of a number”;i
end
Q11. TO accept any number between 1 to 100 and print
whether the number is prime number or not.
CLS
REM “to find the prime numbers between 1 to 100”
for i =1 to 100 step 1
input “enter a number”;n
if(n mod i=0) then
c=c+1
next i
if c=2 then
print “prime number”
else
print “not a prime number”
endif
end

STRING BASED PROGRAMS


[Link]()
This function is used to find the length of the string.
C=len(“RAJENDRA”)
Itwill return 8

Q1. Wap in qbasic to accept a string and find out its length or
how many characters are present in the string.
cls
Input “enter a string”;n$
c=len(n$)
Print “the length of the string is “;c
end

[Link]$(): this function is used to extract the number of


characters from the left.
For eg n$=left$(“computer”,4)
It will return comp from the left to n$.
[Link]$() : this function is used to extract the number of
characters from the right.
For eg :-n$=right$(“computer”,5)
It will return puter to the variable n$

Q2. Wap to accept a word and display the same in the


following pattern
Sample word: BASIC
Sample output: B
B A
B A S
B AS I
BA S I C
Cls
Input “enter the word”;n$
A=len(n$)
For i=1 to A
PRINT LEFT$(N$,I)
NEXT I
END

[Link]$() :- This function is used to convert an uppercase


word or an upper case character into lowercase
For eg p$=”QBASIC”
PRINT LCASE$(P$)
The output will be qbasic

5. UCASE$():- This function is used to convert an LOWERCASE


word or an LOWER case character into uppercase
For eg p$=”qbasic”
PRINT UCASE$(P$)
The output will be QBASIC

You might also like