QBASIC SOLUTION (Chapter 1 ) : Starting Programming



For any type of consultation, query or doubt. You may contact to the following: (+91) 9804 436 193 debabrataguha20@gmail.com 
You will get all the exercise in the Facebook group  https://www.facebook.com/groups/331231161093613/ 



1.     Enter 2 numbers and find the result after addition, subtraction, multiplication and division.

Soln.
INPUT "ENTER TWO NUMBERS"; N1, N2
LET A = N1 + N2
LET S = N1 - N2
LET D = N1 / N2
LET M = N1 * N2

PRINT "THE SUM IS "; A
PRINT "THE DIFFERENCE IS"; S
PRINT "THE PRODUCT IS"; M
PRINT "THE QUOTIENT IS"; D

END



 
2.     Write a program to input your age and mobile number, then print the same.

Soln.

INPUT "ENTER YOUR AGE"; A
INPUT "ENTER YOUR MOBILE NUMBER"; MB
PRINT "THE AGE IS"; A
PRINT "THE MOBILE NUMBER IS"; MB
END



3.     Write a program to print a block F using hash (#), where the F has a height of seven characters and width of five and four characters. 
(
Expected Output
                       ######
                       #
                       #
                       #####
                       #
                       #
                       #
)

Soln.
PRINT "######"
PRINT "#"
PRINT "#"
PRINT "#####"
PRINT "#"
PRINT "#"
PRINT "#"


      
4.     Write a program to compute the perimeter and area of a rectangle with a height of 7 inches. and width of 5 inches.

Soln:
LET H = 7
LET W = 5

LET PERI = 2 * (H + W)
LET AREA = H * W

PRINT "THE PERIMETER OF THE RECTANGLE="; PERI; "INCHES"
PRINT "THE AREA OF THE RECTANGLE="; AREA; "INCHES"

END


            
5.      Write a program to compute the perimeter and area of a circle with a radius of 6 inches.

Soln.
LET R = 6
LET P = 2 * (22 / 7) * R
LET A = (22 / 7) * R ^ 2

PRINT "THE CIRCUMFERENCE IS"; P; "INCHES"
PRINT "THE AREA IS "; A; "SQUARE INCHES"

END

Alternative Soln.

LET R = 6
LET P = 2 * 3.14 * R
LET A = 3.14 * R ^ 2

PRINT "THE CIRCUMFERENCE IS"; P; "INCHES"
PRINT "THE AREA IS "; A; "SQUARE INCHES"

END

      
6.     Enter 2 sides of a rectangle and find the area and perimeter.

Soln.
INPUT "ENTER THE LENGTH AND BREADTH"; L, B
LET AREA = L * B
LET PERI = 2 * (L + B)

PRINT "THE AREA IS"; AREA
PRINT "THE PERIMETER IS"; PERI

END


7.     Write a program that takes hours and minutes as input, and calculates the total number of minutes.

Soln.
INPUT "ENTER HOURS"; H
INPUT "ENTER MINUTES"; M

LET T = (H * 60) + M
PRINT "THE TOTAL NO. OF MINUTES IS"; T; "MINUTES"

END

 

8.     Enter the length in meter and find the equivalent in centimeter and kilometer.

Soln.
INPUT "ENTER LENGTH IN METER"; M
LET KM = M / 1000
LET CM = M * 100

PRINT "THE LENGTH IN KILOMETER IS"; KM
PRINT "THE LENGTH IN CENTIMETER IS"; CM

END

 

9.      Write a program to find the third angle of a triangle if two angles are given

Soln.
INPUT "ENTER THE MEASURE TWO ANGLES OF A TRIANGLE"; A, B

LET C = 180 - (A + B)
PRINT "THE THIRD ANGLE IS"; C

END

 
        
10.  Enter the temperature in centigrade and find the equivalent in Fahrenheit.

Soln.
INPUT "ENTER THE TEMPERATURE IN CENTIGRADE"; C

LET F = (C * 9 / 5) + 32
PRINT "THE TEMPERATURE IN FARENHEIT IS"; F

END


11.  Enter the radius of a circle and find the area, diameter and perimeter.

Soln.
INPUT "ENTER THE RADIUS OF A CIRCLE"; R

LET DIA = 2 * R
LET AREA = (22 / 7) * R ^ 2
LET PERI = 2 * (22 / 7) * R

PRINT "THE DIAMETER IS"; DIA
PRINT "AREA IS="; AREA
PRINT "THE PERIMETER IS="; PERI

END

 
       
12.  Write a program that calculates the volume of a sphere. Volume of a sphere is (4/3)*Ï€ *r3

Soln.
INPUT "ENTER THE RADIUS"; R

LET VS = (4 / 3) * (22 / 7) * R ^ 3
PRINT "THE VOLUME OF SPHERE IS"; VS

END


13.  Write a program that converts kilometers per hour to miles per hour. (1km = 0.621371 miles)

Soln.
INPUT "ENTER THE SPEED IN KILOMETER PER HOUR"; KMH
LET MPH = KMH * 0.621371
PRINT "THE SPEED IN MILES PER HOUR"; MPH
END

 

14.  Write a program to read an amount (integer value) and break the amount into smallest possible number of bank notes.

Soln.
INPUT "enter amount"; a

c = INT(a / 2000)
PRINT "2000 rs note count ="; c
a = a MOD 2000

c = INT(a / 500)
PRINT "500 rs note count:"; c
a = a MOD 500

c = INT(a / 100)
PRINT "100 rs note count="; c
a = a MOD 100

c = INT(a / 50)
PRINT "50 rs note count="; c
a = a MOD 50

c = INT(a / 20)
PRINT "20 rs note count="; c
a = a MOD 20

c = INT(a / 10)
PRINT "10 rs note count="; c
a = a MOD 10

c = INT(a / 5)
PRINT "5 rs note count="; c
a = a MOD 5

c = INT(a / 2)
PRINT "2 rs note count="; c
a = a MOD 2

c = INT(a / 1)
PRINT "1 rs note count="; c

END

 


15.  Enter a number and find the cube and square of the number.

Soln.
INPUT "ENTER A NUMBER"; N1
LET SQ = N1 ^ 2
LET CB = N1 ^ 3

PRINT "THE SQUARE OF THE NUUMBER IS"; SQ
PRINT "THE CUBE OF THE NUMBER IS"; CB

END



 
16.  Enter a number find the double and triple of that number.

Soln.
INPUT "ENTER A NUMBER"; N1

LET DN = N1 * 2
LET TN = N1 * 3

PRINT "THE DOUBLE OF THE NUMBER IS"; DN
PRINT "THE TRIPLE OF THE NUMBER IS"; TN

END




17.  Enter time in seconds , then show it in the Hour: Minute : Second format.

Soln.
INPUT "TIME IN SECONDS"; T

H = INT(T / 3600)
T = T MOD 3600
M = INT(T / 60)
S = T MOD 60

PRINT "THE TIME IN HOURS="; H
PRINT "THE TIME IN MINUTES"; M
PRINT "THE TIME IN SECONDS="; S

END


18.  Write a program to convert a given integer (in days) to years, months and days, assumes that all months have 30 days and all years have 365 days.


Input no. of days: 2535
Expected Output:
6 Year(s)
11 Month(s)
15 Day(s).

Soln.
INPUT "ENTER NO. OF DAYS"; D

LET Y = INT(D / 365)
LET D = D MOD 365
LET M = INT(D / 30)
LET D = D MOD 30

PRINT "THE TIME IN YEAR IS"; Y
PRINT "THE TIME IN MONTHS IS"; M
PRINT "THE TIME IN DAYS IS"; D

END 



19.  Enter 2 numbers and store it into 2 variables a and b respectively. Swap the values of the variable.

Soln.
INPUT "ENTER TWO NUMBERS"; A, B

C = B
B = A
A = C

PRINT “ AFTER SWAPPING THE VALUES ARE
PRINT "B="; B
PRINT "A="; A

END



20.  Enter 2 numbers and store it into 2 variables a and b respectively. Swap the values of the variable without using a third variable.

Soln.
INPUT "ENTER TWO MUNBERS"; A, B

LET A = A + B
LET B = A - B
LET A = A - B

PRINT “ AFTER SWAPPING THE VALUES ARE
PRINT "A="; A
PRINT "B="; B

END


21.  Enter u,t and f and then find the distance (s) using the formula s=ut+(1/2)*ft2

Soln.
INPUT "ENTER THREE NUMBERS"; U, T, F

LET DIST = U * T + (1 / 2) * (F * T) ^ 2
PRINT "THE DISTANCE IS"; DIST

END




22.  Enter 2 numbers and find the modulus without using the modulus operator (%).

Soln.
INPUT "ENTER TWO MUNBERS"; A, B

LET C = INT ( A / B )
LET D = B * C
LET E = A - D

PRINT “ THE REMAINDER IS “ ; E

END



23.  Write a program to enter P, T, R and calculate Simple Interest.
(

Formula is A=P ( 1 + RT )

Where A is the Accumulated amount of Principal Amount P with R rate of Interest for T no. of years 
)

Soln.
INPUT "ENTER PRINCIPAL,RATE AND TIME"; P, R, T
LET SI = (P * R * T) / 100
PRINT "THE SIMPLE INTEREST IS"; SI
END




24.  Write a program to enter P, T, R,N and calculate Compound Interest.
(
         Formula is A=P ( 1 + R/N)NT

         Where A is the Accumulated amount of Principal Amount P with R rate of Interest for T no. of years and N is the no. of times interest is compounded per year
)


Soln.
INPUT "ENTER PRINCIPAL,RATE,TIME AND INTERVAL "; P, R, T , N

LET CI = (P * R / N) ^ ( N * T )
PRINT "THE COMPOUND INTEREST IS"; CI

END



25.  Write a program to enter base and height of a right angled triangle and find its area.
(
Area of a right angled triangle is (1/2) * base * height
)

Soln.
INPUT "ENTER BASE AND HEIGHT"; B, H

LET AREA = (1 / 2) * B * H
PRINT "THE AREA IS"; AREA

END



26.  Write a program to enter the coordinates (x,y) of 2 points and find the distance between those 2 points.
(
Distance between point1 (x1,y1) and point2 (x2,y2) is square root of (x1-x2)2+ (y1-y2)2
)

Soln.
INPUT “Enter the x coordinate of 1st point ” ; X1
INPUT “Enter the y coordinate of 1st point ” ; Y1

INPUT “Enter the x coordinate of 2nd point ” ; X2
INPUT “Enter the y coordinate of 2nd point ” ; Y2

D    = (  (x1 – x2) ^ 2  +  (y1 – y2) ^ 2  )  ^ 0.5

PRINT “ THE DISTANCE IS ” ; D

END



27.  Write a program to enter two timings with hour, minute and second. Then add them and print the answer in the same format.
(
Suppose the 1st timing is: 5 hour 50 mins 40 seconds
And the 2nd timing is : 2 hour 20 mins 50 seconds

The sum of 2 timings will be: 8 hour 11 mins 30 seconds
)

Soln.
PRINT "ENTER 1ST TIMING"

INPUT "ENTER HOUR"; H1
INPUT "ENTER MINUTE"; M1
INPUT "ENTER SECOND"; S1

PRINT "ENTER 2ND TIMING"

INPUT "ENTER SECOND HOUR"; H2
INPUT "ENTER SECOND MINUTE"; M2
INPUT "ENTER SECOND SECOND"; S2

TS = S1 + S2
S = TS MOD 60
TM = M1 + M2 + INT(TS / 60)
M = TM MOD 60
H = H1 + H2 + INT(TM / 60)

PRINT "HOUR="; H
PRINT "MINUTE="; M
PRINT "SECOND="; S

END






Comments

Popular posts from this blog

Java concepts Theory