Branching Problems
Reading Time: 8 minutes
Number Problems
Review programs in BASIC to solve simple numerical problems.
Finding Sign of Number
Write a program in BASIC that takes input from user a number and then prints its sign or zero.
Example 1
----------
Enter a number: 1430
Number is positive.
Example 2
----------
Enter a number: -4862
Number is negative.
Example 3
----------
Enter a number: 0
Number is zero.Determining Even or Odd
Write a program in BASIC that takes input from user a number and then prints if the number is even or odd.
Enter a number: 16796
It is an even number.Determining Divisibility
Write a program in BASIC that takes a number N and a factor F from user and determines if N is divisible by F.
Example 1
----------
Enter a number: 42
Enter a factor: 7
The number is divisible by 7.
Example 2
----------
Enter a number: 54
Enter a factor: 8
The number is divisible not by 8.Finding Minimum
Write a program in BASIC that takes input from user two numbers in variables A, B and then prints the variable name that contains the smaller value.
Enter A: 4862
Enter B: 1430
Smaller number is: 1430Simple Daily Problems
Solve simple real-life problems in BASIC that involves branching.
Determining Citizen Class
You are asked to develop a program in your complex so that people residing there can only watch the common public TV serials only based on his/her age.
Write a program in BASIC that takes an age A from user and decides if the person is a minor, adult or senior citizen and then prints the programs they can watch.
| Age | Class | Can Watch |
|---|---|---|
| $00-17$ | Minor | Cartoons |
| $18-59$ | Adult | TV Series |
| $60$ and above | Senior | Devotionals |
Example 1
----------
Enter an age: 85
The person is senior.
He/She can watch devotionals!
Happy Watching!
Example 2
----------
Enter an age: 27
The person is adult.
He/She can watch TV series!
Happy Watching!
Example 3
----------
Enter an age: 12
The person is minor.
He/She can watch cartoons!
Happy Watching!
Example 4
----------
Enter an age: -30
Error: Age cannot be negative.
Happy Watching!Determine Weekday Name
Write a program in BASIC that takes a weekday number D from user and prints the weekday name.
\[ \begin{aligned} 1 &= \text{Sunday} \\ 2 &= \text{Monday} \\ &\cdots \\ 7 &= \text{Saturday} \\ \end{aligned} \]
Example 1
----------
Enter day number: 5
Thursday.
Example 2
----------
Enter day number: 2
Monday.
Example 3
----------
Enter day number: 8
Error: A week has only seven days.Geometrical Problems
Solve simple geometric problems in BASIC that involves branching.
Determineing Angle Type
Write a program in BASIC that takes an angle A from user and decides if the angle is acute, obtuse or right angle.
Example 1
----------
Enter an angle: 45
It is an acute angle.
Example 2
----------
Enter an angle: 90
It is an right angle.
Example 3
----------
Enter an angle: 135
It is an obtuse angle.
Example 3
----------
Enter an angle: -270
Error: Angle cannot be negative.Determining Triangle Validity
Write a program in BASIC that takes three angles A, B and C from user and determines if they can form a triangle.
\[ \text{Three angles can form a triangle if and only if they sum up to exactly 180}\degree \]
Example 1
----------
Enter angle A: 45
Enter angle B: 45
Enter angle C: 90
The angles can form a triangle.
Example 2
----------
Enter angle A: 45
Enter angle B: 60
Enter angle C: 30
The angles cannot form a triangle.Determining Special Angle Pairs
Write a program in BASIC that takes two angles A and B from user and determines if they are special or not.
\[ \text{Two angles are complementary if they sum up to exactly 90}\degree \\ \text{Two angles are supplementary if they sum up to exactly 180}\degree \]
Example 1
----------
Enter angle 1: 135
Enter angle 2: 45
The angles form special angle pairs.
Example 2
----------
Enter angle 1: 60
Enter angle 2: 30
The angles form special angle pairs.
Example 3
----------
Enter angle 1: 50
Enter angle 2: 85
The angles do not form special angle pairs.Determining Triangle Inequality
Write a program in BASIC that takes three sides A, B and C from user and determines if they can form a triangle. The sum of the lengths of any two sides of a triangle is greater than the length of the third side
\[ \text{Three sides can form a triangle if and only if the sum of two sides is greater than the third side} \]
Example 1
----------
Enter side A: 3
Enter side B: 4
Enter side C: 5
The sides can form a triangle.
Example 2
----------
Enter angle A: 4
Enter angle B: 3
Enter angle C: 10
The sides cannot form a triangle.Determining Point Location
Write a program in BASIC that takes coordinates X and Y from user and determines the location of point in origin, x-axis, y-axis, or any of the quadrant.
Example 1
----------
Enter x coordinate: 0
Enter y coordinate: 0
Point is at origin.
Example 2
----------
Enter x coordinate: 5
Enter y coordinate: 0
Point is in x-axis.
Example 3
----------
Enter x coordinate: 0
Enter y coordinate: 5
Point is in y-axis.
Example 4
----------
Enter x coordinate: 5
Enter y coordinate: 5
Point is in one of the quadrant.