Sequential Problems

Reading Time: 6 minutes


Printing Information

Write a program in BASIC that takes input from user his/her details and then prints it back on screen.

Enter your name:   Abhimanyu
Enter your gender: M
Enter your age:    16
Enter your height: 213.36

Your name is:   Abhimanyu
Your gender is: M
Your age is:    16
Your height is: 213.36

Welcome Human!
INPUT "Enter your name:   ", NAME
INPUT "Enter your gender: ", GENDER
INPUT "Enter your age:    ", AGE
INPUT "Enter your height: ", HEIGHT

PRINT "Your name is:   ", NAME
PRINT "Your gender is: ", GENDER
PRINT "Your age is:    ", AGE
PRINT "Your height is: ", HEIGHT

PRINT "Welcome Human!"

Geometrical Problems

Review programs in BASIC to solve simple geometrical problems.

Finding Perimeter and Area

Write a program in BASIC that takes length L and width W of a rectangle from user and calculates the perimeter and area of the rectangle.

\[ \begin{aligned} \text{Perimeter of a rectangle} &= 2 \times (\text{length} + \text{width}) \\ \text{Area of a rectangle} &= \text{length} \times \text{width} \\ \end{aligned} \]

Enter length of rectangle: 5
Enter width of rectangle:  7

Perimeter of rectangle is: 24
Area of rectangle is:      35
INPUT "Enter length of rectangle: ", L
INPUT "Enter width of rectangle:  ", W

P = 2 * (L + W)
A = L * W

PRINT "Perimeter of rectangle is: ", P
PRINT "Area of rectangle is:      ", A

Finding Circumference and Area

Write a program in BASIC that takes radius R of a circle from user and calculates the circumference and area of the circle.

\[ \begin{aligned} \text{Circumference of a circle} &= 2 \times \pi \times \text{radius} \\ \text{Area of a circle} &= \pi \times \text{radius}^2 \\ \pi &= 3.14 \end{aligned} \]

Enter radius of circle: 5

Circumference of circle is: 31.42
Area of circle is:          78.54
INPUT "Enter radius of circle: ", R

C = 2 * 3.14 * R
A = 3.14 * R * R

PRINT "Circumference of circle is: ", C
PRINT "Area of circle is:          ", A

Finding Surface Area and Volume

Write a program in BASIC that takes one side S of a cube from user and calculates the volume and surface area of the cube.

\[ \begin{aligned} \text{Volume of a cube} &= \text{side} \times \text{side} \times \text{side} \\ \text{Surface area of a cube} &= 6 \times \text{side} \times \text{side} \\ \end{aligned} \]

Enter side of cube: 4

Surface area of cube is: 96
Volume of cube is:       64
INPUT "Enter side of cube: ", S

A = 6 * (S * S)
V = S * S * S

PRINT "Surface area of cube is: ", A
PRINT "Volume of cube is:       ", V

Percentage Problems

Review programs in BASIC to solve simple real-life percentage related problems.

Finding Percentage of Marks

Class teachers have a tiring task of calculating the percentage of marks obtained in science subjects for each students. To help them out, your class decides to ease their task.

Write a program in BASIC that takes marks obtained by a student in Biology B, Physics P, and Chemistry C, along with the total marks T of all the three subject and calculate the percentage of marks obtained in science subjects by a student.

\[ \text{Marks obtained} = \frac{\text{Marks obtained in (Biology + Physics + Chemistry)}}{\text{Total marks of science subjects}} \times 100 \]

Enter marks obtained in Biology:   80
Enter marks obtained in Chemistry: 78
Enter marks obtained in Physics:   85
Enter total marks of all subjects: 300

Marks obtained in Science subjects: 81
INPUT "Enter marks obtained in Biology:   ", B
INPUT "Enter marks obtained in Chemistry: ", C
INPUT "Enter marks obtained in Physics:   ", P
INPUT "Enter total marks of all subjects: ", T

PERCENT = ((B + C + P) / T) * 100

PRINT "Marks obtained in Science subjects: ", PERCENT

Finding Simple Interest

One of your rich relative is in a business of giving out loans. Being in a loan business, he often has to calculate simple interest. So, you decided to ease his task of finding interest payable by clients.

Write a program in BASIC that takes from user a principal amount P, annual rate of interest R, and time of loan T and calculates the simple interest and total amount payable at the end of loan period.

\[ \begin{aligned} \text{Interest} &= \text{Principal} \times \text{Time} \times \frac{Rate}{100} \\ \text{Amount} &= \text{Interest} + \text{Principal} \\ \end{aligned} \]

Enter principal amount: 25000
Enter interest rate:    2.5
Enter time elapsed:     3

Interest payable:     1875
Total amount payable: 26875
INPUT "Enter principal amount: ", P
INPUT "Enter interest rate:    ", R
INPUT "Enter time elapsed:     ", T

I = (P * R * T) / 100
A = P + I

PRINT "Interest payable:     ", I
PRINT "Total amount payable: ", A

Finding Gain Percentage

Sneha owns a stationery shops and wants to make a certain gain on each item she sells. Help her out by writing a program for her.

Write a program in BASIC for her that takes the cost price CP of an item and the gain percentage GP she wants and then calculate the selling price of the item.

\[ \text{Selling price} = \text{Cost price} \times \left( 1 + \frac{\text{Gain \%}}{100} \right) \]

Enter cost price of item: 50
Enter gain percentage:    30

Selling price will be: 65
INPUT "Enter cost price of item: ", CP
INPUT "Enter gain percentage:    ", GP

SP = CP * (1 + (GP / 100))

PRINT "Selling price will be: ", SP

SI Unit Problems

SI units is the future. Yet, people still tend to use the old-school British sytem of units instead of the new standards of units. To help people out and make remarkable change on the society, you decided to write a bunch of programs to convert older units to newer SI units.

Converting Gram to Kilogram

Write a program in BASIC that takes a weight G in grams from user and prints the corresponding weight in Kilogram.

Enter weight (in G): 2500

Weight (in KG) is: 2.5
INPUT "Enter weight (in G): ", G

KG = G / 1000

PRINT "Weight (in KG) is: ", KG

Converting Fahreinheit to Celsius

Write a program in BASIC that takes a temperature F in Fahreinheit from user and prints the corresponding temperature in Celsius.

Enter temperature (in F): 98.2

Temperature (in C) is: 36.8
INPUT "Enter temperature (in F): ", F

C = 5 * (F - 32) / 9

PRINT "Temperature (in C) is: ", C

Converting H:M:S to Seconds

Write a program in BASIC that takes hours H, minutes M, and seconds S from user and prints the corresponding time in seconds.

Enter hour:    42
Enter minutes: 14
Enter seconds: 5

Total seconds: 152045
INPUT "Enter hour:    ", H
INPUT "Enter minutes: ", M
INPUT "Enter seconds: ", S

S = S + (M * 60) + (H * 60 * 60)

PRINT "Total seconds: ", S