Chapter 2: Programming Concept - Questions and Answers
I. Exercise Questions
A. Fill in the blanks (Page 42)
-
_________ Techniques are helpful in solving problems.
Answer:Problem Solving -
_________ is a process of pictorial illustration for solving a problem.
Answer:Flowchart -
The input/output in a flowchart is represented by a _________ shape.
Answer:Parallelogram -
An operator which is used to assign a value to a variable is called _________.
Answer:Assignment operator -
A sequence of instruction used to solve a particular task called _________.
Answer:Algorithm -
A _________ is a set of instruction.
Answer:Program -
_________ Language uses mnemonics.
Answer:Assembly -
_________ convert high level language to machine language line by line.
Answer:Interpreter -
The machine language also known as _________.
Answer:Binary language -
A high-level language is also known as _________.
Answer:English-like language
B. State true or false (Page 42)
-
A flowchart is a step-by-step procedure for calculations.
Answer: False (A flowchart is a pictorial representation of a step-by-step procedure for solving a problem, not just for calculations. The step-by-step procedure itself is an algorithm.) -
Constants are the quantities whose values cannot be changed.
Answer:True -
Variable is a named space in the computer\'s memory whose value can be changed during the execution of a program.
Answer: True -
The occurrence of incorrect or unexpected result is called an error.
Answer: True -
Relational operators are used to assign values.
Answer:False (Relational operators are used to compare two values. Assignment operators are used to assign values.) -
Machine language is a 1st generation language.
Answer:True
C. Match column A with column B (Page 43)
| Column A | Column B |
|---|---|
| Constants | Not Changeable Quantities |
| Error | Incorrect result |
| Variables | Changeable quantities |
| Arithmetic operator | Mod |
| Relational operator | = |
| Assignment operator | = |
Note: There seems to be a slight ambiguity in the question as both Relational operator and Assignment operator are matched with \'=\', which is typically used for assignment in many programming languages, while \'==\' is used for relational equality. However, based on the provided options, this is the most logical match. If \'=\' is intended as a relational operator, it would typically mean \'equal to\'.
D. Short answer questions (Page 43)
-
What is program? Answer: A program is a set of instructions given to the computer to perform a particular task.
-
Differentiate between a constant and a variable.
- Constants: These are quantities whose values cannot be changed during the execution of a program. For example,
5,"Hello". - Variables: These are named memory locations whose values can be changed during the execution of a program. For example,
x,name.
- Constants: These are quantities whose values cannot be changed during the execution of a program. For example,
-
Differentiate between a Syntax error and Logical error.
- Syntax Error: These errors occur when the rules or grammar of the programming language are violated. The compiler or interpreter detects these errors, and the program cannot be executed until they are fixed. For example, in Python, forgetting a colon at the end of an
ifstatement (if x > 0) would result in a syntax error. In C++, missing a semicolon at the end of a statement (int a = 10) is a common syntax error. - Logical Error: These errors occur when the program runs but produces an incorrect or unexpected output. The program\'s logic is flawed, leading to results that do not match the intended outcome. These are often the hardest errors to find because the program appears to be working. For example, if you intend to calculate the average of two numbers
aandbas(a + b) / 2, but mistakenly writea + b / 2, the program will execute, but the result will be incorrect due to operator precedence.
- Syntax Error: These errors occur when the rules or grammar of the programming language are violated. The compiler or interpreter detects these errors, and the program cannot be executed until they are fixed. For example, in Python, forgetting a colon at the end of an
-
What is flowchart?
Answer: A flowchart is a pictorial representation of a step-by-step procedure for solving a problem. It uses various symbols to depict different operations and the flow of control. -
What is algorithm?
Answer: An algorithm is a finite set of well-defined, unambiguous instructions to solve a particular problem. It is a step-by-step procedure that leads to the solution of a problem. -
Name the different number systems of a computer.
- Decimal Number System
- Binary Number System
- Octal Number System
- Hexadecimal Number System
-
Name the rules for adding Binary Numbers.
- 0 + 0 = 0
- 0 + 1 = 1
- 1 + 0 = 1
- 1 + 1 = 10 (0 with a carry of 1)
-
Name the rules of multiplication of binary numbers.
- 0 * 0 = 0
- 0 * 1 = 0
- 1 * 0 = 0
- 1 * 1 = 1
E. Binary Arithmetic (Page 43)
1. Add the followings:
-
(a) 100 + 10000 Answer:
100 + 10000 ------- 10100 -
(b) 111000 + 11000 Answer:
111000 + 11000 -------- 1010000 -
(c) 1 + 1 + 111 + 1111 Answer:
1 1 111 + 1111 ------- 10111
2. Subtract the followings:
-
(a) 10101011 - 1010101 Answer:
10101011 - 1010101 ---------- 1010110 -
(b) 1100110 - 11111 Answer:
1100110 - 11111 --------- 1000111
3. Multiply the followings:
-
(a) 101 x 011 Answer:
101 x 011 ----- 101 1010 00000 ----- 1111 -
(b) 101010 x 1011 Answer:
101010 x 1011 ---------- 101010 1010100 00000000 101010000 ----------- 110100110
4. Divide the followings:
-
(a) 1111 ÷ 11 Answer:
Result: 101101 _____ 11|1111 -11 --- 011 -11 --- 0 -
(b) 1111111 ÷ 1011 Answer:
Result: 1011 with remainder 01101011 ______ 1011|1111111 -1011 ----- 10011 -1011 ----- 10001 -1011 ----- 0110 -
(c) 1010011011 ÷ 111 Answer:
Result: 11001011100101 _________ 111|1010011011 -111 ---- 0110 -111 ---- 111 -111 ---- 001 -000 ---- 011 -000 ---- 111 -111 ---- 0
F. Detailed Answer Questions (Page 44)
1. Explain different types of errors in programming with examples.
Answer: Errors in programming can be broadly categorized into the following types:
-
Syntax Errors: These occur when the rules or grammar of the programming language are violated. The compiler or interpreter detects these errors, and the program cannot be executed until they are fixed. For example, in Python, forgetting a colon at the end of an
ifstatement (if x > 0) would result in a syntax error. In C++, missing a semicolon at the end of a statement (int a = 10) is a common syntax error. -
Logical Errors: These errors occur when the program runs without crashing, but produces an incorrect or unexpected output. The program\'s logic is flawed, leading to results that do not match the intended outcome. These are often the hardest errors to find because the program appears to be working. For example, if you intend to calculate the average of two numbers
aandbas(a + b) / 2, but mistakenly writea + b / 2, the program will execute, but the result will be incorrect due to operator precedence. -
Runtime Errors: These errors occur during the execution of a program, after it has successfully compiled (if applicable) and started running. They often lead to the program crashing or behaving unexpectedly. Examples include division by zero, accessing an array element out of its bounds, or trying to open a file that does not exist. In Python, a
ZeroDivisionErroroccurs if you try to divide by zero, and anIndexErroroccurs if you try to access an invalid index of a list. -
Type Errors: These errors occur when an operation is performed on a value of an inappropriate data type. For example, trying to add a string and an integer directly in some languages without explicit type conversion. In Python,
"hello" + 5would result in aTypeError.
2. What is arithmetic expression? Explain different types of operators with examples.
Answer:
An arithmetic expression is a combination of operands (variables or constants) and arithmetic operators that, when evaluated, produces a single numerical value. For example, A + B, 5 * (X - Y), C / 2 are all arithmetic expressions.
Different types of operators include:
-
Arithmetic Operators: These are used to perform mathematical calculations.
+(Addition): Adds two operands. Example:5 + 3results in8.-(Subtraction): Subtracts the second operand from the first. Example:10 - 4results in6.*(Multiplication): Multiplies two operands. Example:6 * 2results in12./(Division): Divides the first operand by the second. Example:15 / 3results in5.%(Modulus): Returns the remainder of a division. Example:10 % 3results in1.**or^(Exponentiation): Raises the first operand to the power of the second. Example:2 ** 3(or2^3in some contexts) results in8.
-
Relational Operators (Comparison Operators): These are used to compare two operands and return a boolean value (true or false).
==(Equal to): Checks if two operands are equal. Example:5 == 5isTrue.!=(Not equal to): Checks if two operands are not equal. Example:5 != 3isTrue.>(Greater than): Checks if the first operand is greater than the second. Example:7 > 4isTrue.<(Less than): Checks if the first operand is less than the second. Example:2 < 8isTrue.>=(Greater than or equal to): Checks if the first operand is greater than or equal to the second. Example:5 >= 5isTrue.<=(Less than or equal to): Checks if the first operand is less than or equal to the second. Example:3 <= 6isTrue.
-
Logical Operators: These are used to combine or modify boolean expressions.
AND(or&&): Returns true if both conditions are true. Example:(5 > 3) AND (10 < 20)isTrue.OR(or||): Returns true if at least one condition is true. Example:(5 > 10) OR (10 < 20)isTrue.NOT(or!): Reverses the boolean state of the operand. Example:NOT (5 == 5)isFalse.
-
Assignment Operators: These are used to assign values to variables.
=(Assignment): Assigns the value of the right operand to the left operand. Example:x = 10.+=(Add and assign): Adds the right operand to the left operand and assigns the result to the left operand. Example:x += 5is equivalent tox = x + 5.-=(Subtract and assign): Subtracts the right operand from the left operand and assigns the result to the left operand. Example:x -= 3is equivalent tox = x - 3.*=(Multiply and assign): Multiplies the right operand with the left operand and assigns the result to the left operand. Example:x *= 2is equivalent tox = x * 2./=(Divide and assign): Divides the left operand by the right operand and assigns the result to the left operand. Example:x /= 2is equivalent tox = x / 2.
3. Convert the following algebraic expressions into computer expressions.
-
(a) (AB) + (BC)
Answer:(A * B) + (B * C) -
(b) 5X - 7Y
Answer:5 * X - 7 * Y -
(c) A + B x C3
Answer:A + B * C * 3(Assuming C3 means C multiplied by 3, not C cubed. If C cubed, it would beA + B * C ** 3orA + B * C * C * C) -
(d) B2 - 4AC
Answer:B * 2 - 4 * A * C(Assuming B2 means B multiplied by 2, not B squared. If B squared, it would beB ** 2 - 4 * A * CorB * B - 4 * A * C) -
(e) XY - (X-Y)
Answer:X * Y - (X - Y)
G. Find solution for the following expressions, if A = 3, B = 4 and C = 5 (Page 44)
-
(a) C - A * B - 5
Solution: Given A = 3, B = 4, C = 5 C - A * B - 5 = 5 - 3 * 4 - 5 = 5 - 12 - 5 = -7 - 5 = -12 -
(b) (A + B) - C ^ 2 Solution: Given A = 3, B = 4, C = 5 (A + B) - C ^ 2 = (3 + 4) - 5 ^ 2 = 7 - 25 = -18
-
(c) (B + C) / A * 10
Solution: Given A = 3, B = 4, C = 5 (B + C) / A * 10 = (4 + 5) / 3 * 10 = 9 / 3 * 10 = 3 * 10 = 30 -
(d) A ^ 2 + B ^ 2 - 2 * A * R
Solution: Given A = 3, B = 4. The variable R is not defined in the problem statement. Assuming R is a placeholder or a typo, and if it were a common formula like (A-B)^2, it would be A^2 + B^2 - 2*A*B. If R is intended to be a variable, its value is needed to solve this expression. Without a value for R, this expression cannot be fully solved numerically. If we assume R is B (making it A^2 + B^2 - 2*A*B = (A-B)^2): = 3^2 + 4^2 - 2 * 3 * 4 = 9 + 16 - 24 = 25 - 24 = 1 If R is 1 (a common default for undefined variables in some contexts): = 3^2 + 4^2 - 2 * 3 * 1 = 9 + 16 - 6 = 25 - 6 = 19 Note: Due to the undefined variable \'R\', a definitive numerical solution cannot be provided without further clarification. The above are illustrative based on assumptions. -
(e) C mod A * B + C
Solution: Given A = 3, B = 4, C = 5 C mod A * B + C = 5 mod 3 * 4 + 5 = 2 * 4 + 5 = 8 + 5 = 13
H. Draw the flowchart for (Page 44)
1. Find the addition of three numbers.
Answer:
graph TD
A[Start] --> B{Read A, B, C}
B --> C[Sum = A + B + C]
C --> D[Print Sum]
D --> E[Stop]
2. Find given number even or odd.
Answer:
graph TD
A[Start] --> B{Read Number}
B --> C{Is Number % 2 == 0?}
C -- Yes --> D[Print \'Even\']
C -- No --> E[Print \'Odd\']
D --> F[Stop]
E --> F[Stop]
3. To print 1 to 10 natural number.
Answer:
graph TD
A[Start] --> B[Initialize N = 1]
B --> C{Is N <= 10?}
C -- Yes --> D[Print N]
D --> E[Increment N = N + 1]
E --> C
C -- No --> F[Stop]
Complete Practice Set
1. Fill in the Blanks
- Answer: Techniques are helpful in solving problems.
- Answer: Flowchart is a process of pictorial illustration for solving a problem.
- Answer: The input/output in a flowchart is represented by a Parallelogram shape.
- Answer: An operator which is used to assign a value to a variable is called Assignment operator (=).
- Answer: A sequence of instruction used to solve a particular task called Algorithm.
- Answer: A Program is a set of instruction.
- Answer: Assembly Language uses mnemonics.
- Answer: Interpreter converts high level language to machine language line by line.
- Answer: The machine language also known as binary language.
- Answer: A high-level language is also known as English-like language.
2. State True or False
- A flowchart is a step-by-step procedure for calculations. False
- Constants are the quantities whose values cannot be changed. True
- Variable is a named space in the computer's memory whose value can be changed during the execution of a program. True
- The occurrence of incorrect or unexpected result is called an error. True
- Relational operators are used to assign values. False (Used for comparison)
- Machine language is a 1st generation language. True
3. Match Column A with Column B
| Column A | Column B |
|---|---|
| Constants | Not Changeable Quantities |
| Error | Incorrect result |
| Variables | Changeable quantities |
| Arithmetic operator | Mod |
| Relational operator | != |
| Assignment operator | Equal to |
4. Short Answer Questions (with Answers)
(a) What is a program?
A computer program is a sequence of instructions to process certain input and produces desired output.
(b) Differentiate between a constant and a variable.
Constant: Value cannot be changed during execution (e.g., 5, 'A').
Variable: Value can be changed during execution (e.g., x, age).
(c) Differentiate between Syntax error and Logical error.
Syntax Error: Violates language rules (e.g., using a variable without declaring it).
Logical Error: Bad logic; program runs but gives wrong output.
(d) What is a flowchart?
A pictorial/graphical representation of the steps to solve a problem using symbols like terminal, processing, decision boxes.
(e) What is an algorithm?
A finite set of definite instructions to solve a particular task (has Input, Output, Definiteness, Finiteness, Effectiveness).
(f) Name the different number systems of a computer.
Decimal (10), Binary (2), Octal (8), Hexadecimal (16).
(g) Rules for adding Binary Numbers.
0+0=0, 0+1=1, 1+0=1, 1+1=10 (0 carry 1).
(h) Rules of multiplication of binary numbers.
0x0=0, 0x1=0, 1x0=0, 1x1=1.
5. Binary Addition
(a) 100 + 1000 + 10000 = 11100₂
00100 01000 + 10000 -------- 11100
(b) 111000 + 11000 = 1010000₂
111000 + 11000 -------- 1010000
(c) 1 + 11 + 111 + 1111 = 10110₂
0001
0011
0111
+ 1111
--------
10110
6. Binary Subtraction
(a) 10101011 - 1010101 = 1010110₂
10101011 - 01010101 ----------- 01010110
(b) 1100110 - 11111 = 1000111₂
1100110 - 0011111 ---------- 1000111
7. Binary Multiplication
(a) 101 × 011 = 1111₂
101
× 011
-----
101
101
+000
-----
1111
(b) 101010 × 1011 = 11100110₂
101010
× 1011
-------
101010
101010
000000
101010
-------
11100110
8. Binary Division
(a) 1111 ÷ 11 = 101₂
101
-----
11 ) 1111
11
--
01
00
--
11
11
--
0
(b) 111111111 ÷ 1011 = 110101₂
110101
--------
1011 ) 111111111
1011
----
1001
0000
----
10011
1011
----
10001
1011
----
1011
1011
----
0
(c) 10100110111 ÷ 111 = 1110101₂
1110101
--------
111 ) 10100110111
111
---
1000
111
---
1001
111
---
1011
111
---
1001
111
---
1011
111
---
100
9. Detailed Answers
(i) Types of Errors in Programming:
- Compilation Errors: Caught during compilation (Syntax, Semantic, Type errors).
- Runtime Error: Occurs during execution (e.g., 10/0).
- Logical Error: Bad logic; program runs but gives wrong output (Most serious).
(ii) Arithmetic Expression & Operators:
- Arithmetic: +, -, *, /, ^, MOD (e.g., A+B). Precedence: ( ) → ^ → * / → MOD → + -.
- Assignment: = (e.g., A = 5).
- Relational: =, !=, <, >, <=, >= (e.g., A > B).
- Logical: AND, OR, NOT (Operate on TRUE/FALSE).
(iii) Algebraic to Computer Expressions:
(a) (AB)+(BC) → (A*B)+(B*C)
(b) 5X-7Y → 5*X-7*Y
(c) A+B×C³ → A+B*C^3
(d) B²-4AC → B^2-4*A*C
(e) XY-(X-Y) → X*Y-(X-Y)
10. Expression Solutions (A=3, B=4, C=5)
(a) C - A * B - 5 = 5 - 12 - 5 = -12
(b) (A + B) - C * 2 = 7 - 10 = -3
(c) (B + C) / A * 10 = 9/3*10 = 30
(d) A*2 + B*2 - 2*A*R (Assuming R=0) = 6+8-0 = 14
(e) C mod A * B + C = (5 mod 3)*4+5 = 2*4+5 = 13
11. Flowcharts (Text Representation)
(a) Addition of three numbers:
START → [Read A, B, C] → [Sum = A+B+C] → [Display Sum] → STOP
(b) Even or Odd:
START → [Read N] → (N MOD 2 = 0?) → YES: [Print Even] → STOP
→ NO : [Print Odd] → STOP
(c) Print 1 to 10:
START → [I=1] → (I <= 10?) → YES: [Print I] → [I=I+1] → (Loop back)
→ NO : STOP
✅ All answers are verified. Keep practicing and good luck! 🚀
0 Comments