Samacheer Kalvi Class 11 Computer Science Chapter 10 Flow of Control

Get the most accurate TN Board Solutions for Class 11 Computer Science Chapter 10 Flow of Control here. Updated for the 2026-27 academic session, these solutions are based on the latest TN Board textbooks for Class 11 Computer Science. Our expert-created answers for Class 11 Computer Science are available for free download in PDF format.

Detailed Chapter 10 Flow of Control TN Board Solutions for Class 11 Computer Science

For Class 11 students, solving TN Board textbook questions is the most effective way to build a strong conceptual foundation. Our Class 11 Computer Science solutions follow a detailed, step-by-step approach to ensure you understand the logic behind every answer. Practicing these Chapter 10 Flow of Control solutions will improve your exam performance.

Class 11 Computer Science Chapter 10 Flow of Control TN Board Solutions PDF

Book Evaluation

Part I

Choose The Correct Answer

 

Question 1. What is the alternate name of null statement?
(a) No statement
(b) Empty statement
(c) Void statement
(d) Zero statement
Answer: (b) Empty statement
In simple words: A null statement is like an empty instruction in programming, meaning it does nothing. It's often called an empty statement because it literally has no operation.

๐ŸŽฏ Exam Tip: Remember that a null statement is simply a semicolon; its purpose is to create an executable line that performs no action, often used in loops or conditionals where a statement is syntactically required but no action is desired.

 

Question 2. In C++, the group of statements should enclosed within:
(a) { }
(b) [ ]
(c) ( )
(d) < >
Answer: (a) { }
In simple words: In C++, you use curly braces, like these { }, to group several programming instructions together. This creates a block of code, which helps organize your program.

๐ŸŽฏ Exam Tip: Curly braces `{}` define a block of code, typically used for function bodies, loops, and conditional statements. This is fundamental for code structure.

 

Question 3. The set of statements that are executed again and again in iteration is called as:
(a) condition
(b) loop
(c) statement
(d) body of loop
Answer: (d) body of loop
In simple words: When a computer program does the same actions many times, the part of the code that keeps repeating is called the body of the loop. It contains the instructions that are performed in each cycle.

๐ŸŽฏ Exam Tip: Distinguish between the 'loop' (the overall structure for repetition) and the 'body of the loop' (the specific statements that get repeated). The loop body is key to what the loop actually achieves.

 

Question 4. The multi way branching statement:
(a) if
(b) if... else
(c) switch
(d) for
Answer: (c) switch
In simple words: A switch statement is a special command that lets a program choose one of many paths based on a single value. It's like having many doors and picking one to go through.

๐ŸŽฏ Exam Tip: Recognize that a `switch` statement is excellent for handling multiple choices based on a single variable's value, offering a cleaner alternative to a long chain of `if-else if` statements.

 

Question 5. How many types of iteration statements?
(a) 2
(b) 3
(c) 4
(d) 5
Answer: (b) 3
In simple words: In programming, there are three main kinds of statements that make a computer repeat tasks. These are the `for` loop, the `while` loop, and the `do-while` loop, each used for different repeating jobs.

๐ŸŽฏ Exam Tip: Remember the three primary iteration statements in C++: `for`, `while`, and `do-while` loops. Each serves a distinct purpose in controlling repetition.

 

Question 6. How many times the following loop will execute?
for (int i=0; i<10; i++)

(a) 0
(b) 10
(c) 9
(d) 11
Answer: (b) 10
In simple words: This loop starts counting from 0 and continues as long as the number is less than 10. It will run for numbers 0 through 9, which means it runs exactly 10 times.

๐ŸŽฏ Exam Tip: When calculating loop iterations, carefully check the initial value, the condition (`<` vs. `<=`), and how the counter changes. A loop from `0` to `<10` runs 10 times (0-9).

 

Question 7. Which of the following is the exit control loop?
(a) for
(b) while
(c) do...while
(d) if-else
Answer: (c) do...while
In simple words: An exit control loop checks its condition after running the code inside the loop at least once. The `do-while` loop is an example, as it always performs the actions first, then decides whether to repeat.

๐ŸŽฏ Exam Tip: Understand that `do-while` is an exit-controlled loop because its condition is checked *after* the loop body executes, guaranteeing at least one execution. In contrast, `for` and `while` are entry-controlled.

 

Question 8. Identify the odd one from the keywords of jump statements:
(a) break
(b) switch
(c) go to
(d) continue
Answer: (b) switch
In simple words: `break`, `go to`, and `continue` are commands that change how a program moves through its code in a special way, like jumping to another spot or skipping parts. `switch` is a different type of command used for making choices, not for jumping.

๐ŸŽฏ Exam Tip: Jump statements (`break`, `continue`, `goto`) alter the normal flow of execution directly. A `switch` statement, however, is a selection statement that chooses among multiple paths, not a jump statement.

 

Question 9. Which of the following is the exit control loop?
(a) do-while
(b) for
(c) while
(d) if-else
Answer: (a) do-while
In simple words: The `do-while` loop is the one that always runs its instructions at least one time before checking if it needs to repeat. This means it controls the exit, not the entry, to the loop.

๐ŸŽฏ Exam Tip: A key characteristic of an exit-controlled loop like `do-while` is its guarantee of executing the loop body at least once, regardless of the initial condition, which is checked at the end.

 

Question 10. A loop that contains another loop inside its body:
(a) Nested loop
(c) In line loop
Answer: (a) Nested loop
In simple words: When you put a loop inside another loop, the inner loop is called a nested loop. It's like having a small repeated task inside a bigger repeated task.

๐ŸŽฏ Exam Tip: Nested loops are essential for tasks like processing 2D arrays (e.g., matrices), generating patterns, or performing operations where an inner iteration depends on an outer iteration.

Part - II

Short Answers

 

Question 1. What is a null statement and compound statement?
Answer: A null statement is a programming instruction that contains only a semicolon `;` and performs no action. It is also called an empty statement. For example, a loop with a null statement as its body might look like `for (int i=0; i<10; i++);`.
A compound statement, also known as a block, is a group of statements enclosed within a pair of curly braces `{}`. This grouping allows multiple statements to be treated as a single unit. For example, a compound statement's general format is:
`{`
`statement1;`
`statement2;`
`statement3;`
`}`
In simple words: A null statement does nothing and is just a semicolon. A compound statement is when you put many commands inside curly braces to make them act like one big command.

๐ŸŽฏ Exam Tip: Clearly define both terms and provide simple code examples for each. For compound statements, emphasize that the curly braces group multiple lines into a single logical unit.

 

Question 2. What is a selection statement? Write its types?
Answer: A selection statement helps a program make decisions based on a condition. If the condition is true, one set of instructions is carried out; otherwise, a different set of instructions (or none) is executed. It is also known as a decision statement.
The types of selection statements are:
1. Two-way branching (e.g., `if-else`)
2. Multiway branching (e.g., `if-else if-else` ladder, `switch`)
In simple words: A selection statement lets your program choose what to do next based on a "yes" or "no" answer to a question. There are two main kinds: one where you choose between two paths, and another where you pick from many paths.

๐ŸŽฏ Exam Tip: When explaining selection statements, highlight their role in enabling decision-making in programs. For types, remember the common structures like `if-else` for two-way and `switch` or `if-else if` for multiway branching.

 

Question 3. Correct the following code segment:
if (x=1)
p= 100;
else
P = 10;

Answer: The original code uses a single equals sign (`=`), which is an assignment operator, inside the `if` condition. This assigns the value `1` to `x` and then checks if `x` (which is now `1`) is true, making the `if` part always execute. To compare `x` with `1`, a double equals sign (`==`), which is the equality operator, should be used.
Correct code:
`if (x==1)`
`p= 100;`
`else`
`p = 10;`
In simple words: The mistake was using `=` (assign) instead of `==` (compare) inside the `if` statement. The corrected code uses `==` to truly check if `x` is equal to 1.

๐ŸŽฏ Exam Tip: A common error in programming is confusing the assignment operator (`=`) with the equality comparison operator (`==`). Always double-check your conditions in `if` statements to ensure you are comparing values, not assigning them.

 

Question 4. What will be the output of the following code:
int year;
cin >> year;
if (year % 100 == 0)
if (year % 400 == 0)
cout << "Leap year";
else
cout << "Not Leap year";
If the input is given is
(i) 2000
(ii) 2003
(iii) 2010

Answer: The code checks if a given `year` is a leap year. A year is a leap year if it is divisible by 400, or if it is divisible by 4 but not by 100.
(i) Input: `2000`
Output: `Leap year`
Explanation: `2000 % 100 == 0` is true, and `2000 % 400 == 0` is also true, so it's a leap year.
(ii) Input: `2003`
Output: `Not Leap year`
Explanation: `2003 % 100 == 0` is false. The outer `if` condition fails, and the `else` associated with the first `if` is not directly shown here, but a year that is not divisible by 4 is generally not a leap year. This year is not divisible by 4.
(iii) Input: `2010`
Output: `Not Leap year`
Explanation: `2010 % 100 == 0` is false. Similar to 2003, this year is also not divisible by 4, so it is not a leap year. This logic ensures accurate leap year determination.
In simple words: The code tells you if a year is a "leap year" or "not a leap year". For 2000, it's a leap year because it can be divided by 400. For 2003 and 2010, they are not leap years because they don't fit the rules, like not being divisible by 4.

๐ŸŽฏ Exam Tip: When analyzing nested `if-else` statements, carefully match each `else` with its corresponding `if`. Indentation can sometimes be misleading; always remember that an `else` matches the closest preceding `if` without an `else`.

 

Question 5. What will be the output of the following code?
for (int i=2; i<= 10; i+=2)
cout << i;

Answer: This `for` loop starts with `i` at 2, continues as long as `i` is less than or equal to 10, and increases `i` by 2 in each step. It prints the value of `i` in each iteration.
Output:
`246810`
In simple words: The program will print numbers starting from 2, then 4, 6, 8, and finally 10. It adds 2 each time until it reaches 10.

๐ŸŽฏ Exam Tip: Pay close attention to the loop's initialization, condition, and update expression (`i+=2`). This type of loop is common for printing sequences with a constant step, like even numbers.

 

Question 6. How many times the following loop will execute?
for (int i=21; i<31; i++)
cout << "value of i:" << i << endl;

Answer: This `for` loop initializes `i` to 21. It continues as long as `i` is less than 31, and `i` increases by 1 in each step. The loop will print the "value of i:" for `i` from 21 up to 30. Therefore, the loop executes 10 times.
Output:
`Value of i: 21`
`Value of i: 22`
`Value of i: 23`
`Value of i: 24`
`Value of i: 25`
`Value of i: 26`
`Value of i: 27`
`Value of i: 28`
`Value of i: 29`
`Value of i: 30`
In simple words: The code will print "value of i:" followed by numbers from 21 to 30. It counts up one by one until it reaches 30. This means it will print 10 lines in total.

๐ŸŽฏ Exam Tip: To calculate the exact number of iterations, use the formula `(final_value - initial_value) / step + 1` if the condition is inclusive (`<=`), or `(final_value - initial_value) / step` if exclusive (`<`). Here, `(31 - 21) / 1 = 10` iterations.

 

Question 7. Write a while loop that displays numbers 2,4, 6, 8.......20.
Answer: Here is a C++ `while` loop that displays even numbers from 2 to 20:
`#include `
`using namespace std;`
`int main() {`
` int i = 2;`
` while(i <= 20) {`
` cout << i << " ";`
` i = i + 2;`
` }`
` return 0;`
`}`
This loop starts with `i` as 2. The `while` condition `i <= 20` checks if `i` is 20 or less. Inside the loop, `i` is printed, and then `i` is increased by 2. This process repeats until `i` is greater than 20.
In simple words: This program uses a `while` loop to show numbers that start at 2 and go up to 20, adding 2 each time. It will print 2, 4, 6, and so on, until 20.

๐ŸŽฏ Exam Tip: When writing `while` loops, ensure you correctly initialize the loop control variable before the loop, define a clear termination condition, and update the variable inside the loop to avoid an infinite loop.

 

Question 8. Compare an if and a ? : operator.
Answer: The `if` statement checks a condition: if true, a specific block of code (the true-block) runs; otherwise, a different block (the false-block) runs. This structure allows the program to make decisions and execute different sets of statements. An `if` statement can contain one or more statements within its blocks.
The conditional operator (`? :`), also known as the ternary operator, offers a concise alternative to a simple `if-else` statement. It also evaluates a condition, but if true, it returns one value or expression; if false, it returns another. It is typically used for short, single-expression decisions rather than executing entire blocks of code. For example, `(condition) ? expression1 : expression2;`
In simple words: The `if` statement helps your program make big decisions, letting it run different parts of code. The `? :` operator is like a shortcut for smaller choices, giving back one of two values based on a simple "yes" or "no" question.

๐ŸŽฏ Exam Tip: While the conditional operator `? :` provides a compact way to express simple `if-else` logic, always use `if-else` for executing multiple statements or for more complex branching to maintain code readability.

Part - III

Short Answers

 

Question 1. Convert the following if-else to a single conditional statement:
if (x >= 10)
a = m + 5:
else
a = m;

Answer: The provided `if-else` block assigns a value to `a` based on the condition `x >= 10`. This can be rewritten more compactly using the conditional (ternary) operator `? :`.
Single conditional statement:
`a = (x >= 10) ? (m + 5) : m ;`
Here, `(x >= 10)` is the condition. If it's true, `(m + 5)` is assigned to `a`; otherwise, `m` is assigned to `a`. Parentheses around `m + 5` are good for clarity.
In simple words: You can write the same decision in one line using a special `? :` symbol. It asks "Is x greater than or equal to 10?" If yes, `a` becomes `m + 5`; if no, `a` becomes `m`.

๐ŸŽฏ Exam Tip: The conditional operator is a powerful tool for simplifying code, especially when assigning a value based on a condition. Ensure the syntax `condition ? value_if_true : value_if_false` is correct.

 

Question 2. Rewrite the following code so that it is functional:
v = 5;
do;
total + = v;
while v <=10
cout << total;

Answer: The original code has several issues, including an empty `do` block, incorrect syntax for `while` (missing parentheses and semicolon), and missing curly braces for the `do-while` body and the `while` condition. The `total` variable is also not initialized.
Correct code:
`int v = 5;`
`int total = 0; // Initialize total`
`do {`
` total += v;`
` v++; // Increment v to avoid infinite loop and make condition eventually false`
`} while (v <= 10);`
`cout << total;`
This corrected code initializes `total` to 0, correctly increments `v` inside the loop, and properly structures the `do-while` loop with braces, ensuring it functions as intended to sum `v` values.
In simple words: The original code had many small mistakes, like an empty `do` section and wrong `while` loop setup. The fixed code adds a starting value for `total`, correctly adds `v` to `total` each time, and makes sure `v` grows so the loop can stop. It uses proper curly braces to group the commands.

๐ŸŽฏ Exam Tip: Always initialize variables before use. When constructing `do-while` loops, remember that `do` block requires curly braces if it contains multiple statements, and the `while` condition must be followed by a semicolon `;` and contain the condition in parentheses.

 

Question 3. Write a C++ program to print the multiplication table of a given number.
Answer: This C++ program asks the user for a number and then displays its multiplication table from 1 to 10.
`#include `
`using namespace std;`
`int main () {`
` int num;`
` cout << "Enter Number to find its multiplication table: ";`
` cin >> num;`
` for (int a = 1; a <= 10; a++) {`
` cout << num << " * " << a << " = " << num * a << endl;`
` }`
` return 0;`
`}`
The program first prompts the user to enter a number. Then, a `for` loop iterates from 1 to 10, and in each iteration, it calculates and prints the product of the input number and the current loop counter, effectively displaying the multiplication table.
In simple words: This program asks you for a number. Then, it uses a loop to multiply that number by 1, then by 2, and so on, up to 10. It prints each multiplication sum, showing you the whole table.

๐ŸŽฏ Exam Tip: When writing programs for multiplication tables, ensure the loop correctly iterates through the desired range (e.g., 1 to 10) and that the output format clearly shows the multiplication expression and its result.

 

Question 4. Write the syntax and purpose of switch statement.
Answer: The `switch` statement in C++ is a multi-way branching statement that allows a program to choose among several execution paths based on the value of a single expression. It provides a cleaner and more efficient way to handle multiple choices compared to a long chain of `if-else if` statements.
Syntax of the `switch` statement:
`switch (expression) {`
` case constant1:`
` statement(s);`
` break;`
` case constant2:`
` statement(s);`
` break;`
` // ... more cases ...`
` default:`
` statement(s);`
`}`
The `expression` is evaluated once, and its value is compared against the `constant` values in each `case` label. If a match is found, the statements for that `case` are executed until a `break` statement is encountered or the `switch` block ends. The `default` case is optional and executes if no `case` matches.
In simple words: The `switch` statement helps a program pick one option out of many based on what a certain value is. It's like a menu where you choose a dish, and the `break` command stops it from trying to choose more. If no choice matches, it goes to a "default" option.

๐ŸŽฏ Exam Tip: Always include a `break` statement at the end of each `case` block to prevent "fall-through" into the next case. The `default` case is good practice for handling unexpected values.

 

Question 5. Write a short program to print following series: a) 1 4 7 10...... 40
Answer: This C++ program generates and prints the series 1, 4, 7, 10, ..., up to 40. Each number in the series is 3 more than the previous one.
`#include `
`using namespace std;`
`int main() {`
` for (int i = 1; i <= 40; i = i + 3) {`
` cout << i << " ";`
` }`
` return 0;`
`}`
The `for` loop initializes `i` to 1, continues as long as `i` is less than or equal to 40, and increments `i` by 3 in each iteration (`i = i + 3`). The value of `i` is printed in each step.
In simple words: This program starts at the number 1 and keeps adding 3 to it. It prints each new number until it goes past 40. So it will print 1, 4, 7, 10, and so on.

๐ŸŽฏ Exam Tip: For arithmetic series programs, the key is to correctly set the loop's starting value, the termination condition, and the increment step. Double-check the `<= ` or `<` in the condition to include or exclude the boundary value.

Part - IV

Explain In Detail

 

Question 1. Explain the control statement with a suitable example.
Answer: Control statements are special instructions in programming that change the usual, step-by-step order in which a program's instructions are executed. They allow programs to perform tasks sequentially, make decisions (branching), or repeat actions (iteration). Every programming language includes control statements to manage these fundamental program flows.

One type is the **Selection statement** (also called a decision statement): This statement helps a program make a choice about which block of code to run. It evaluates a condition; if the condition is true, one set of statements (the true-block) is executed; otherwise, a different set (the false-block) is executed, or no action is taken. This helps in executing different code paths based on whether a certain criteria is met.

Here is a flowchart example of a selection statement (e.g., `if-else`):
Entry Condition True STATEMENT 2 False STATEMENT 1 Exit
Another type is the **Iteration statement**: This is used for repeating a set of statements multiple times until a certain condition is no longer met. Examples include `for`, `while`, and `do-while` loops.
In simple words: Control statements are like traffic rules for your program, telling it when to go straight, turn left, or repeat a path. They help the program make decisions or do tasks over and over.

๐ŸŽฏ Exam Tip: When describing control statements, always categorize them into sequence, selection (branching), and iteration (looping). For examples, use simple, common programming constructs like `if-else` for selection and `for` or `while` for iteration.

 

Question 2. What entry control loop? Explain any one of the entry control loops with a suitable example.
Answer: An entry-controlled loop is a type of loop where the test condition is evaluated *before* the body of the loop is executed. This means the loop body will only run if the condition is true. If the condition is false from the start, the loop body will not execute even once. Examples of entry-controlled loops include `while` and `for` statements.

**Working of the `while` loop:**
A `while` loop is a control flow statement that repeatedly executes a block of statements as long as a specified condition remains true. It is considered an entry-controlled loop because its test expression is checked at the beginning of each iteration, before any statements inside the loop are processed.

The `while` loop syntax is:
`while (Test expression) {`
` Statement-x;`
`}`

In a `while` loop, the program first checks the `Test expression`. If it is true, the `Statement-x` inside the loop's body is executed. After `Statement-x` completes, the control returns to the `while` condition, and the `Test expression` is evaluated again. This cycle continues until the `Test expression` becomes false, at which point the loop terminates, and control passes to the statement immediately following the loop. This ensures the loop body runs only when the condition permits. This structure is often visualized with a flowchart.

Here is a flowchart for a `while` loop (iteration statement):
Test expression Condition True Body of while Loop False The Exit Condition
**Example:** A program to calculate the sum of numbers from 1 to 10 using a `while` loop.
`#include `
`using namespace std;`
`int main() {`
` int i = 1, sum = 0;`
` while (i <= 10) {`
` sum = sum + i;`
` i++;`
` }`
` cout << "The sum of 1 to 10 is " << sum << endl;`
` return 0;`
`}`
Output: `The sum of 1 to 10 is 55`
This program correctly calculates the sum because `i` is initialized to 1, the condition `i <= 10` is checked before each addition, and `i` is incremented, ensuring proper iteration.
In simple words: An "entry control loop" checks a rule before it does any work. If the rule is true, it does the work; if not, it skips it. A `while` loop is one such loop: it keeps doing a job as long as its rule is true. If the rule is false at the start, it won't even do the job once.

๐ŸŽฏ Exam Tip: When discussing entry-controlled loops, emphasize that the condition check *precedes* execution, which is the defining characteristic that distinguishes them from exit-controlled loops. Always provide a clear, simple code example to illustrate.

 

Question 3. Write a program to find the LCM and GCD of two numbers.
Answer:
PROGRAM:
using namespace std;
#include <iostream>
int main()
{
int n1, n2, i, gcd;
cout << "Enter two integers:";
cin >> n1 >> n2;
for(i = 1; i <= n1 && i <= n2; ++i)
{
// Checks if i is factor of both integers
if(n1 % i == 0 && n2 % i == 0)
gcd = i;
}
int lcm = n1 * n2 / gcd;
cout << "\nG.C.M. OF " << n1 << " and " << n2 << " is " << gcd;
cout << "\nL.C. M. OF " << n1 << " and " << n2 << " is " << lcm;
return 0;
}
The program calculates the Greatest Common Divisor (GCD) by checking all numbers up to the smaller of the two inputs. The Least Common Multiple (LCM) is then found using the formula: \( \text{LCM} = (\text{number1} \times \text{number2}) / \text{GCD} \).
In simple words: This program takes two numbers from the user. It then finds their greatest common divisor (the biggest number that divides both) and their least common multiple (the smallest number that both can divide into).

๐ŸŽฏ Exam Tip: Remember the formula for LCM using GCD, as it is a quick way to find LCM once GCD is calculated: \( \text{LCM}(a, b) = \frac{|a \times b|}{\text{GCD}(a, b)} \).

 

Question 4. Write programs to find the sum of the following series: a) \( x-\frac{x^2}{2!} + \frac{x^3}{3!} - \frac{x^4}{4!} + \frac{x^5}{5!} - \frac{x^6}{6!} \) b) \( x+\frac{x^2}{2} + \frac{x^3}{3} +....+ \frac{x^n}{n} \)
Answer:
(a) For the series \( x-\frac{x^2}{2!} + \frac{x^3}{3!} - \frac{x^4}{4!} + \frac{x^5}{5!} - \frac{x^6}{6!} \):
PROGRAM
using namespace std;
#include<iostream>
int main()
{
int i,x,n,f=1,sign=1;
float sum=0,t;
cout<<"\nEnter N valueโ€;
cin>>n;
cout<<"\nEnter x value ...";
cin>>x;
t=x;
for(i=1;i<=n;i++)
{
f = f * i;
sum = sum + sign * t/f;
t = t * x;
sign = -sign;
}
cout<<"SUM OF THE SERIES = "<<sum;
return 0;
}
This program calculates the sum of the alternating series up to 'n' terms. It keeps track of the factorial and the power of 'x' using a loop, and alternates the sign for each term.
(b) For the series \( x+\frac{x^2}{2} + \frac{x^3}{3} +....+ \frac{x^n}{n} \):
PROGRAM
using namespace std;
#include<iostream>
int main()
{
int i,x,n;
float sum=0,t;
cout<<"\nEnter N valueโ€;
cin>>n;
cout<<"\nEnter x value ...";
cin>>x;
t=x;
for(i=1;i<=n;i++)
{
sum = sum + t/i;
t = t * x;
}
cout<<"SUM OF THE SERIES = "<<sum;
return 0;
}
This program calculates the sum of the series where each term is \( x \) raised to a power and divided by that power. It adds terms iteratively until 'n' terms are reached.
In simple words: These programs add up numbers in a special pattern called a series. Part (a) adds terms with signs that switch (plus, then minus) and uses factorials. Part (b) adds terms where x is raised to a power and then divided by that same power.

๐ŸŽฏ Exam Tip: Pay close attention to the formula for each series, especially how the denominator (factorial or just the number) and the sign change for alternating series. Incorrect signs or denominators are common errors.

 

Question 5. Write a program to find sum of the series s=1 +x +x\(^2\) + ... +x\(^n\).
Answer:
PROGRAM
using namespace std;
#include<iostream>
int main()
{
int sum=1,x,i,t,n;
cout<<"\nEnter N valueโ€;
cin>>n;
cout<<"\nEnter x value ... ";
cin>>x;
t=x;
for(i=1;i<=n;i++)
{
sum = sum + t;
t = t * x;
}<
cout<<"SUM = "<<sum;
return 0;
}
This program calculates the sum of a geometric series \( 1 + x + x^2 + \dots + x^n \). It starts `sum` at 1 (for the first term) and then iteratively adds \( x, x^2, \dots, x^n \) by multiplying `t` by `x` in each loop.
In simple words: This program figures out the total sum of a series like \( 1 + x + x \times x + x \times x \times x \) and so on, up to a certain number of terms given by the user.

๐ŸŽฏ Exam Tip: For geometric series starting with 1, make sure to initialize your sum variable to 1 to correctly include the first term \( x^0 \).

11th Computer Science Guide Flow of Control Additional Questions and Answers

Choose The Correct Answer 1 Mark

 

Question 1. The empty statement is otherwise called as ....................
(a) Control statement
(b) Zero statement
(c) Null statement
(d) Block statement
Answer: (c) Null statement
In simple words: A null statement, also known as an empty statement, is a programming command that does nothing.

๐ŸŽฏ Exam Tip: Know the different names for programming concepts, as questions often use synonyms to test your understanding.

 

Question 2. The basics of control structure are................ statement.
(a) Selection
(b) Iteration
(c) Jump
(d) All of the options
Answer: (d) All of the options
In simple words: Control structures include ways to choose what code runs (selection), repeat code (iteration), and move to different parts of the code (jump).

๐ŸŽฏ Exam Tip: Understand the three main categories of control flow statements: sequential, selection (conditional), and iteration (looping/jump) statements. These are fundamental to programming.

 

Question 3. Iteration statement is called as ....................
(a) Null statement
(b) Block statement
(c) Selection statement
(d) Looping statement
Answer: (d) Looping statement
In simple words: Iteration statements are also known as looping statements because they make a set of instructions run over and over again.

๐ŸŽฏ Exam Tip: Remember that "iteration" and "looping" are interchangeable terms when discussing control flow in programming.

 

Question 4. In a program, the action may be ......................
(a) Variable declarations
(b) Expression evaluations
(c) Assignment operations
(d) All of the options
Answer: (d) All of the options
In simple words: Inside a program, you can declare variables, calculate things using expressions, and give values to variables.

๐ŸŽฏ Exam Tip: Be aware that a single program can involve all these fundamental actions, and they often work together within control structures.

 

Question 5. ............ is a multi-path decision-making statement.
(a) if
(b) if-else
(c) else - if
(d) if-else ladder
Answer: (d) if-else ladder
In simple words: An if-else ladder helps a program make choices from many options, like climbing steps to pick a door.

๐ŸŽฏ Exam Tip: An if-else ladder is used when there are multiple conditions to check, and each condition leads to a different set of actions, providing a clear path for decision-making.

 

Question 6. The ............ is a statement containing only a semicolon.
(a) Null
(b) Empty statement
(c) Both (a) and (b)
(d) None of the options
Answer: (c) Both (a) and (b)
In simple words: A statement that only has a semicolon is called both a null statement and an empty statement, and it does nothing.

๐ŸŽฏ Exam Tip: Recognize that "null statement" and "empty statement" are synonyms, both referring to a statement that consists only of a semicolon.

 

Question 8. C++ allows a group of statements enclosed by pair of ....................braces.
(a) ()
(b) { }
(c) []
(d) < >
Answer: (b) { }
In simple words: In C++, curly braces `{}` are used to group several statements together, like a single block of code.

๐ŸŽฏ Exam Tip: Curly braces are essential for defining blocks of code in C++, such as for function bodies, loops, and conditional statements, to ensure multiple statements are treated as one unit.

 

Question 9. C++ supports types of iteration statements.
(a) 3
(b) 2
(c) 4
(d) 5
Answer: (a) 3
In simple words: C++ programming language has three main kinds of loops: for loops, while loops, and do-while loops.

๐ŸŽฏ Exam Tip: Know the three primary iteration statements in C++: `for`, `while`, and `do-while`, and understand when to use each for effective looping.

 

Question 10. .................... statements alter the sequence of flow of instructions.
(a) Control
(b) Null
(c) Compound
(d) None of the options
Answer: (a) Control
In simple words: Control statements change the usual order in which a program runs its instructions.

๐ŸŽฏ Exam Tip: Control statements are crucial for programming logic as they dictate the path of execution, allowing for decisions and repetitions.

 

Question 11. .................... is used to transfer the control from one place to another place without any condition in a program.
(a) Break statement
(b) Continue statement
(c) goto statement
(d) All of the options
Answer: (c) goto statement
In simple words: The `goto` statement lets a program jump from one part of the code to another without needing a specific condition to be true.

๐ŸŽฏ Exam Tip: While `goto` exists, it's generally discouraged in modern programming practice due to potential for creating "spaghetti code" that is hard to read and debug.

 

Question 12. The .................... statement are the statements, that are executed one after another only once from top to bottom.
(a) Sequential
(b) Selective
(c) Iterative
(d) None of the options
Answer: (a) Sequential
In simple words: Sequential statements are simply lines of code that run one after the other, from the top to the bottom, without any skips or repeats.

๐ŸŽฏ Exam Tip: Sequential execution is the default flow in most programs, where instructions are processed in the order they appear.

 

Question 13. .................... statements do not alter the flow of execution.
(a) Control
(b) Selective
(c) Iterative
(d) None of the options
Answer: (d) None of the options
In simple words: The question is about statements that *do not* change how a program runs, meaning simple instructions that just do their job in order.

๐ŸŽฏ Exam Tip: Control flow statements, by definition, alter the flow. Statements that don't alter the flow are typically basic sequential operations like variable assignments or print statements.

 

Question 14. .................... statements always end with a semicolon (;).
(a) Sequential
(b) Selective
(c) Iterative
(d) None of the options
Answer: (a) Sequential
In simple words: In programming, most single instructions (sequential statements) must end with a semicolon to tell the computer where one command finishes and the next begins.

๐ŸŽฏ Exam Tip: Missing semicolons are a common syntax error in C++ and similar languages, leading to compilation failures. Remember that `if`, `for`, `while`, and `do-while` *statements* themselves don't end with a semicolon, but the individual *statements* within their blocks usually do.

 

Question 15. The .................... statement means the statement (s) are executed depends upon a condition.
(a) Sequential
(b) Selective
(c) Iterative
(d) None of the options
Answer: (b) Selective
In simple words: A selective statement means that some code will only run if a certain condition is true, allowing the program to choose its path.

๐ŸŽฏ Exam Tip: Selection statements (like `if`, `if-else`, `switch`) are fundamental for decision-making in programs, allowing different code blocks to execute based on specific conditions.

 

Question 16. If a condition is true, a true block (a set of statements) is executed otherwise a false block is executed is called ........... statement.
(a) Iteration
(b) Selection
(c) Jump
(d) Compound
Answer: (b) Selection
In simple words: This type of statement lets a program choose between two groups of code: one runs if a condition is true, and the other runs if it's false.

๐ŸŽฏ Exam Tip: This describes a classic `if-else` structure, which is the most basic form of a selection statement for binary choices.

 

Question 17. The .................... statement is a set of the statement are repetitively executed depends upon conditions.
(a) Sequential
(b) Selective
(c) Iterative
(d) None of the options
Answer: (c) Iterative
In simple words: An iterative statement is like a loop that keeps running a set of commands over and over as long as a certain condition remains true.

๐ŸŽฏ Exam Tip: Iterative statements (loops) are vital for automating repetitive tasks and are controlled by a condition that determines when the repetition stops.

 

Question 18. The condition on which the execution or exit from the loop is called ....................
(a) Exit-condition
(b) Test-condition
(c) Either (a) or (b)
(d) None of the options
Answer: (c) Either (a) or (b)
In simple words: The rule that decides when a loop should stop running is known as both an exit-condition and a test-condition.

๐ŸŽฏ Exam Tip: Understanding the loop's condition is critical to predict its behavior and prevent infinite loops. These terms are often used interchangeably.

 

Question 19. In C++, any non-zero is treated as ................ including negative numbers.
(a) False
(b) True
(c) Complement
(d) None of the options
Answer: (b) True
In simple words: In C++, any number that is not zero is considered true, even if it's a negative number. Only zero is considered false.

๐ŸŽฏ Exam Tip: In C and C++, numerical zero is treated as `false`, and any non-zero value (positive or negative) is treated as `true` in a boolean context.

 

Question 20. In C++, zero is treated as ....................
(a) False
(b) True
(c) Complement
(d) None of the options
Answer: (a) False
In simple words: In C++ programming, the number zero is always seen as 'false' when used in conditions.

๐ŸŽฏ Exam Tip: This convention (0 as false, non-zero as true) is fundamental in C++ for evaluating conditions in `if` statements and loops.

 

Question 21. Decisions in C++ are made using .................... statement.
(a) if..else
(b) switch., case
(c) Either (a) or (b)
(d) None of the options
Answer: (c) Either (a) or (b)
In simple words: C++ programs can make choices using `if-else` statements for simple conditions or `switch-case` statements for multiple options.

๐ŸŽฏ Exam Tip: Both `if-else` and `switch-case` are selection statements used for decision-making; `if-else` is flexible for any condition, while `switch-case` is efficient for multiple choices based on a single variable's value.

 

Question 22. .................... statement which chooses between two alternatives.
(a) if..else
(b) switch., case
(c) Either (a) or (b)
(d) None of the options
Answer: (a) if..else
In simple words: The `if-else` statement is used when a program needs to choose between two different actions based on whether a condition is true or false.

๐ŸŽฏ Exam Tip: `if-else` is the primary construct for binary decision-making, executing one block of code if the condition is met and another if it's not.

 

Question 23. .................... creates branches for multiple alternatives sections of code, depending on the value of a single variable.
(a) if..else
(b) switch., case
(c) Either (a) or (b)
(d) None of the options
Answer: (b) switch., case
In simple words: A `switch-case` statement is a way to choose among many possible actions in a program, where the choice depends on the value of just one variable.

๐ŸŽฏ Exam Tip: Use a `switch-case` statement when you have many fixed choices based on one variable (like an integer or character) to make your code cleaner and easier to read than a long `if-else if` chain.

 

Question 24. .................... is a two-way branching statement.
(a) if..else
(b) switch., case
(c) Either (a) or (b)
(d) None of the options
Answer: (a) if..else
In simple words: A two-way branching statement means the program can go in one of two directions, like choosing between two paths based on a condition, which is what `if-else` does.

๐ŸŽฏ Exam Tip: Two-way branching statements enable a program to perform one action if a condition is true and a different action if it's false, creating distinct paths in the code.

 

Question 25. .................... is a multiple branching statement.
(a) if..else
(b) switch., case
(c) Either (a) or (b)
(d) None of the options
Answer: (b) switch., case
In simple words: A multiple branching statement lets a program choose from several different paths, not just two, based on a single value, which is exactly how `switch-case` works.

๐ŸŽฏ Exam Tip: Multiple branching statements, such as `switch-case` or `if-else if` ladders, are essential for handling complex decision flows with many possible outcomes.

 

Question 27. The nested if can have ................ forms.
(a) four
(b) two
(c) three
(d) five
Answer: (c) three
In simple words: A nested 'if' statement means putting one 'if' statement inside another. It can be nested in three ways: inside the 'if' part, inside the 'else' part, or both.

๐ŸŽฏ Exam Tip: A nested 'if' statement is an 'if' statement inside another 'if' or 'else if' statement. Knowing its forms helps in writing complex conditional logic.

 

Question 28. ................ is nested if form.
(a) If nested inside if part
(b) If nested inside both if part and else part
(c) If nested inside else part
(d) All the options
Answer: (d) All the options
In simple words: You can place an 'if' statement inside another 'if' block, inside an 'else' block, or even inside both the 'if' and 'else' parts of an outer 'if' statement.

๐ŸŽฏ Exam Tip: Understanding the different ways to nest 'if' statements is crucial for handling complex conditions and scoring full marks in logic-based questions.

 

Question 29. The ................ is a multi-path decision-making statement.
(a) if-else ladder
(b) Simple if
(c) if... else
(d) None of the options
Answer: (a) if-else ladder
In simple words: An 'if-else if' ladder helps your program choose from many different options by checking conditions one by one until it finds the right one.

๐ŸŽฏ Exam Tip: An 'if-else if' ladder allows you to choose from many options, checking each condition one by one until a true one is found.

 

Question 30. In .................type of statement 'if' is followed by one or more else if statements and finally end with an else statement.
(a) if-else ladder
(b) Simple if
(c) if... else
(d) None of the options
Answer: (a) if-else ladder
In simple words: This is the specific structure for an 'if-else if' ladder, where you check many conditions in order and have a default action at the end if none of the conditions are true.

๐ŸŽฏ Exam Tip: Recognize the pattern of an 'if-else if' ladder where multiple conditions are checked in sequence, ending with a default 'else'.

 

Question 31. The................ operator is an alternative for the if-else statement.
(a) Conditional
(b) Ternary
(c) Continue
(d) Either A or B
Answer: (d) Either A or B
In simple words: The conditional operator, also called the ternary operator, is a short way to write a simple 'if-else' statement in one line.

๐ŸŽฏ Exam Tip: The conditional operator (?:), also called the ternary operator, is a compact way to write simple 'if-else' logic, making your code shorter.

 

Question 32. The conditional operator consists of ............... symbols.
(a) two
(b) three
(c) four
(d) five
Answer: (a) two
In simple words: The conditional operator uses two special characters: a question mark (?) and a colon (:) to separate its three parts.

๐ŸŽฏ Exam Tip: The conditional operator uses two symbols, '?' and ':', to define its three parts: condition, true result, and false result.

 

Question 33. The conditional operator takes ................ arguments.
(a) two
(b) three
(c) four
(d) five
Answer: (b) three
In simple words: This operator needs three pieces of information to work: the condition to check, what to do if it's true, and what to do if it's false.

๐ŸŽฏ Exam Tip: Remember that the conditional operator needs three pieces of information: a condition to check, a value if true, and a value if false.

 

Question 34. The switch statement is a ............... statement.
(a) Multi-way branch
(b) Two-way branch
(c) Jump
(d) None of these
Answer: (a) Multi-way branch
In simple words: A 'switch' statement allows a program to choose among many different paths based on the value of a single expression.

๐ŸŽฏ Exam Tip: A switch statement is like a special road sign that directs traffic (program flow) to one of many paths based on a single variable's value.

 

Question 35. statement provides an easy way to dispatch execution to different parts of code based on the value of the expression.
(a) if..else
(b) switch
(c) goto
(d) None of these
Answer: (b) switch
In simple words: The 'switch' statement is a good choice when you need to run different code blocks depending on the exact value of one variable or expression.

๐ŸŽฏ Exam Tip: The 'switch' statement is ideal for situations where you need to perform different actions based on a single value, making the code cleaner than many 'if-else if' statements.

 

Question 36. The ................statement replaces multiple if-else sequences.
(a) if..else
(b) switch
(c) go to
(d) None of these
Answer: (b) switch
In simple words: Instead of writing many 'if-else if' statements to check for different values, a 'switch' statement can do the same job in a neater way.

๐ŸŽฏ Exam Tip: Use a 'switch' statement when you have many 'if-else if' checks for the same variable, as it often makes the code easier to read and manage.

 

Question 37. The expression provided in the switch should result in a................ value.
(a) Constant
(b) Variant
(c) Null
(d) None of these
Answer: (a) Constant
In simple words: The value that a 'switch' statement checks must be a fixed, unchanging value, like a number or a character, not something that can change.

๐ŸŽฏ Exam Tip: The 'switch' statement needs a fixed, constant value for each 'case' label, not something that can change during program execution.

 

Question 39. The ................ statement is used inside the switch to terminate a statement sequence.
(a) default
(b) break
(c) continue
(d) None of these
Answer: (b) break
In simple words: The 'break' keyword tells the program to stop executing statements in the current 'switch' case and jump out of the 'switch' block.

๐ŸŽฏ Exam Tip: The 'break' statement is essential in a 'switch' to stop code from running into the next 'case' by mistake, which is called "fall-through".

 

Question 40. In a switch statement, when a ................ statement is reached, the flow of control jumps to the next line following the switch statement.
(a) go to
(b) break
(c) continue
(d) None of these
Answer: (b) break
In simple words: When a 'break' statement is hit, the program immediately leaves the entire 'switch' block and continues with the code written after it.

๐ŸŽฏ Exam Tip: Always remember that 'break' makes the program exit the 'switch' block entirely, moving to the code right after it.

 

Question 42. ................ statement checks for equality as well as for logical expression.
(a) go to
(b) if..else
(c) continue
(d) switch
Answer: (b) if..else
In simple words: An 'if-else' statement can check if two things are equal, or if a whole logical condition (like 'and' or 'or') is true, and then run code based on that.

๐ŸŽฏ Exam Tip: The 'if-else' statement is fundamental for making decisions, allowing your program to perform different actions based on whether a condition is true or false.

 

Question 43. ................ statement uses a single expression for multiple choices.
(a) go to
(b) if..else
(c) continue
(d) switch
Answer: (d) switch
In simple words: A 'switch' statement takes one main value and then lets you specify different actions for several possible outcomes of that value.

๐ŸŽฏ Exam Tip: A 'switch' statement streamlines decision-making when you have many options that depend on the value of one single expression or variable.

 

Question 44. A(n) ................ statement uses multiple statements for multiple choices.
(a) go to
(b) if..else
(c) continue
(d) switch
Answer: (d) switch
In simple words: In a 'switch' statement, each 'case' block can hold more than one instruction, letting you do many things for a single choice.

๐ŸŽฏ Exam Tip: The 'switch' statement is good for situations with many paths because each 'case' can contain several statements, all under one main expression.

 

Question 45. The ................ statement evaluates integer, character, pointer or floating-point type or Boolean type.
(a) go to
(b) if..else
(c) continue
(d) switch
Answer: (b) if..else
In simple words: The 'if-else' statement is very versatile; it can check conditions involving numbers, characters, true/false values, and even memory addresses.

๐ŸŽฏ Exam Tip: The 'if-else' statement is very flexible and can evaluate many different types of conditions, from simple numbers to more complex logical checks.

 

Question 46. ................ statement evaluates only character or an integer data type.
(a) go to
(b) if..else
(c) continue
(d) switch
Answer: (d) switch
In simple words: Unlike 'if-else', a 'switch' statement can only compare its main expression to whole numbers or single characters.

๐ŸŽฏ Exam Tip: Remember that 'switch' statements are limited to integer or character types for their expressions, unlike the more versatile 'if-else' statements.

 

Question 47. If the expression inside the switch statement turns out to be false then ................ statements are executed.
(a) default
(b) true block
(c) else block
(d) None of these
Answer: (a) default
In simple words: If the value you're checking in a 'switch' statement doesn't match any of the 'case' options, the code in the 'default' section will run.

๐ŸŽฏ Exam Tip: The 'default' case in a 'switch' statement acts like the 'else' part of an 'if-else' statement, running if no other 'case' matches.

 

Question 48. If the expression inside if turns out to be false, statement inside ................ will be executed.
(a) default
(b) true block
(c) else block
(d) None of these
Answer: (c) else block
In simple words: When the condition in an 'if' statement is not met, the program skips the 'if' block and moves to execute the 'else' block, if one is present.

๐ŸŽฏ Exam Tip: In an 'if-else' structure, if the 'if' condition is false, the code in the 'else' block will always run.

 

Question 49. The ................ statement is more flexible.
(a) switch
(b) if
(c) continue
(d) None of these
Answer: (b) if
In simple words: The 'if' statement is more adaptable because it can use many types of conditions and complex logic, unlike the 'switch' statement which is limited.

๐ŸŽฏ Exam Tip: The 'if' statement is more flexible because it can handle a wider range of expression types and complex logical conditions compared to 'switch'.

 

Question 50. The ................ statement is more efficient than the if-else statement.
(a) switch
(b) go to
(c) continue
(d) None of these
Answer: (a) switch
In simple words: When you have many choices based on one value, a 'switch' statement can often make your program run faster than a long chain of 'if-else if' statements.

๐ŸŽฏ Exam Tip: For many specific value comparisons, 'switch' statements can sometimes be more optimized and thus faster than long 'if-else if' chains.

 

Question 51. Which is true related to the switch statement?
(a) A switch statement can only work for the quality of comparisons.
(b) No two case labels in the same switch can have identical values.
(c) If character constants are used in the switch statement, they are automatically converted to their equivalent ASCII codes.
(d) All the options
Answer: (d) All the options
In simple words: All the statements about the 'switch' statement are correct: it checks for exact matches, each 'case' must be unique, and characters are treated like their ASCII numbers.

๐ŸŽฏ Exam Tip: All three options correctly describe how a 'switch' statement works, covering its comparison type, unique case values, and character handling.

 

Question 52. When a switch is a part of the statement sequence of another switch, then it is called as ................ switch statement.
(a) Iterative
(b) Sequential
(c) Nested
(d) None of these
Answer: (c) Nested
In simple words: Just like you can put an 'if' inside another 'if', you can also put a 'switch' statement inside another 'switch' statement, which is called nesting.

๐ŸŽฏ Exam Tip: Just like 'if' statements, 'switch' statements can be placed inside other 'switch' statements to create more complex decision structures.

 

Question 53. A(n) ................ is a sequence of one or more statements that are repeatedly executed until a condition is satisfied.
(a) Iteration
(b) Looping
(c) Iteration or Looping
(d) None of these
Answer: (c) Iteration or Looping
In simple words: Both 'iteration' and 'looping' mean repeating a set of instructions many times until a certain condition becomes true or false.

๐ŸŽฏ Exam Tip: Iteration and looping refer to the same concept: repeating a block of code until a certain condition is met, which is fundamental in programming.

 

Question 54. ................ is used to reduce the length of code, to reduce time, to execute the program and takes less memory space.
(a) Iteration
(b) Looping
(c) Iteration or Looping
(d) None of these
Answer: (c) Iteration or Looping
In simple words: Repeating tasks using loops makes your program shorter, faster, and uses less computer memory because you don't write the same code multiple times.

๐ŸŽฏ Exam Tip: Loops are powerful tools for efficiency because they allow you to reuse code blocks for repetitive tasks, saving space and execution time.

 

Question 55. C++supports ................ types of iteration statements.
(a) five
(b) four
(c) three
(d) two
Answer: (c) three
In simple words: C++ programming language provides three main kinds of loops that you can use: 'for' loops, 'while' loops, and 'do-while' loops.

๐ŸŽฏ Exam Tip: C++ has three main types of loops: 'for', 'while', and 'do-while', each suited for different looping needs.

 

Question 56. C++ supports ................ type of iteration statement.
(a) for
(b) while
(c) do..while
(d) All the options
Answer: (d) All the options
In simple words: C++ includes all the common types of loops, giving programmers flexible tools to handle repeating tasks in their programs.

๐ŸŽฏ Exam Tip: C++ provides flexibility by supporting all standard loop types, allowing programmers to choose the best one for each task.

 

Question 57. Every loop has ................ elements.
(a) five
(b) four
(c) three
(d) two
Answer: (b) four
In simple words: Most loops are made up of four key parts: setting a starting point, checking a condition, doing the main task, and changing the starting point.

๐ŸŽฏ Exam Tip: Loops typically consist of four main parts: initialization, condition check, loop body, and update, which work together to control repetition.

 

Question 58. Every loop has ................ element.
(a) Initialization expression
(b) Test expression / Update expression
(c) The body of the loop
(d) All the options
Answer: (d) All the options
In simple words: All the listed parts, like setting up, checking, changing, and the main code, are essential for any loop to work correctly.

๐ŸŽฏ Exam Tip: All listed options are fundamental components found in nearly all programming loops, working in harmony to manage the repetition process.

 

Question 59. The control variable(s) must be initialized ................ the control enters into a loop.
(a) after
(b) before
(c) Either A or B
(d) None of these
Answer: (b) before
In simple words: You must give a starting value to the variable that controls the loop before the loop actually starts running.

๐ŸŽฏ Exam Tip: A control variable must be set to its starting value before the loop begins, so the loop has a clear starting point for its iterations.

 

Question 60. Whose value decides whether the loop-body will be executed or not?
(a) Test expression
(b) Update expression
(c) Initialization expression
(d) None of these
Answer: (a) Test expression
In simple words: The condition that the loop checks each time is what decides if the code inside the loop will run or if the loop will stop.

๐ŸŽฏ Exam Tip: The test expression is the heart of a loop's decision-making, as it continuously checks if the loop should continue or stop.

 

Question 61. In an ................ loop, the test-expression is evaluated before entering into a loop,
(a) Entry-controlled
(b) Exit-controlled
(c) Both A and B
(d) None of these
Answer: (a) Entry-controlled
In simple words: In this type of loop, the program checks the condition at the very beginning, even before it runs the code inside the loop for the first time.

๐ŸŽฏ Exam Tip: Entry-controlled loops (like 'for' and 'while') check the condition first, meaning the loop body might not run even once if the condition is initially false.

 

Question 62. In an ................ loop, the test-expression is evaluated before exiting from the loop.
(a) Entry-controlled
(b) Exit-controlled
(c) Both A and B
(d) None of these
Answer: (b) Exit-controlled
In simple words: For this kind of loop, the condition is checked after the code block has already run once, just before the loop might end.

๐ŸŽฏ Exam Tip: Exit-controlled loops (like 'do-while') guarantee that the loop body will run at least once because the condition is checked only after the first execution.

 

Question 64. ................ statement is executed at the end of the loop after the body of the loop is executed.
(a) Test expression
(b) Update expression
(c) Initialization expression
(d) None of these
Answer: (b) Update expression
In simple words: The part of the loop that changes the loop control variable (like increasing or decreasing a counter) runs after all the main code in the loop has finished.

๐ŸŽฏ Exam Tip: The update expression in a loop typically changes the control variable, moving the loop closer to its termination condition.

 

Question 65. In an ................ loop, first, the test expression is evaluated and if it is nonzero, the body of the loop is executed otherwise the loop is terminated.
(a) Entry-controlled
(b) Exit-controlled
(c) Both A and B
(d) None of these
Answer: (a) Entry-controlled
In simple words: This type of loop checks if a condition is true at the beginning; if it is, the loop runs, otherwise it stops right away.

๐ŸŽฏ Exam Tip: This describes an entry-controlled loop, where the condition is checked upfront, deciding if the loop body will run at all.

 

Question 67. ................ loop statement contains three different statements.
(a) for
(b) while
(c) do..while
(d) All the options
Answer: (a) for
In simple words: The 'for' loop is special because it puts three key steps - starting, checking, and changing - all in one line at the top.

๐ŸŽฏ Exam Tip: The 'for' loop is unique among the three main loop types because it explicitly includes initialization, condition, and update expressions in its header.

 

Question 68. The for statement contains ................ statement
(a) Test expression
(b) Update expression
(c) Initialization expression
(d) All the options
Answer: (d) All the options
In simple words: A 'for' loop is designed to combine all the necessary parts for repetition: setting up a start, checking a condition, and making changes, all in one clear structure.

๐ŸŽฏ Exam Tip: Remember that a 'for' loop combines initialization, condition checking, and updating all in one line, making it compact for fixed iterations.

 

Question 70. The initialization part of the loop is used to initialize variables or declare a variable which is executed ............... time(s).
(a) Loop repeated
(b) Only one
(c) two
(d) None of these
Answer: (b) Only one
In simple words: The initialization part of a loop is run only once when the loop first starts. This step gets the loop ready by setting up variables.

๐ŸŽฏ Exam Tip: When a loop begins, its initialization happens only once to prepare variables, unlike conditions and updates which run repeatedly.

 

Question 71. How many times the following loop will be executed? for (i=0; i <= 10; i++);
(a) 10
(b) 9
(c) 11
(d) None of these
Answer: (c) 11
In simple words: The loop starts with \( i = 0 \) and continues as long as \( i \) is less than or equal to 10. It will run for \( i = 0, 1, 2, ..., 10 \), which counts to 11 times. The semicolon after the loop header makes it an empty loop that just iterates.

๐ŸŽฏ Exam Tip: Pay close attention to the loop's condition and the increment/decrement, especially if it includes "less than or equal to" for boundary cases.

 

Question 72. In C++, the group of statements should be enclosed within ............. braces.
(a) { }
(b) [ ]
(c) ( )
(d) < >
Answer: (a) { }
In simple words: In C++, a group of statements, often called a block, must be placed inside curly braces. This helps to define a single unit of code.

๐ŸŽฏ Exam Tip: Curly braces \( \{ \} \) are essential in C++ for grouping multiple statements into a single block for functions, loops, or conditional statements.

 

Question 73. In for loop, multiple initializations and multiple update expressions are separated by
(a) Semicolons
(b) Colons
(c) Commas
(d) None of these
Answer: (c) Commas
In simple words: When you have many starting or updating parts in a 'for' loop, you separate each one using a comma. This allows more complex setup or changes within a single loop definition.

๐ŸŽฏ Exam Tip: Remember that semicolons separate the three main parts of a for loop (initialization, condition, update), but commas separate multiple items within those parts.

 

Question 74. In a for loop, which expression is optional?
(a) Test expression
(b) Update expression
(c) Initialization expression
(d) All the options
Answer: (d) All the options
In simple words: In a 'for' loop, you can actually skip the starting part, the checking part, and the updating part. Even though you can leave them out, you still need the semicolons to mark their places.

๐ŸŽฏ Exam Tip: While all parts are optional, an empty condition expression always evaluates to true, potentially creating an infinite loop if not handled correctly.

 

Question 75. What will be printed by the following for loop? for(i=0; ++i);
(a) Finite loop
(b) Indefinite loop
(c) No iteration
(d) None of these
Answer: (b) Indefinite loop
In simple words: The loop `for(i=0; ++i);` is an indefinite loop. This is because the test condition `++i` will always be true (non-zero for integers), causing the loop to run forever.

๐ŸŽฏ Exam Tip: An indefinite or infinite loop happens when the condition for the loop to stop is never met, causing it to run endlessly.

 

Question 76. A loop that has no statement in its body is called an ...................
(a) Empty loop
(b) Indefinite loop
(c) Finite loop
(d) None of these
Answer: (a) Empty loop
In simple words: A loop that does nothing inside its main part, meaning it has no statements in its body, is called an empty loop. These loops often use a semicolon right after the loop's header.

๐ŸŽฏ Exam Tip: Empty loops are usually created by mistake when a semicolon is accidentally placed after a loop's header, causing the loop body to be ignored.

 

Question 77. Identify the empty loop from the following.
(a) for(i+0 ; i<=5; +=i);
(b) for(i+0; i<=5; +=i); {cout<<"C++";>
(c) for(i+0 ; i<=5; +=i) { }
(d) All the options
Answer: (c) for(i+0 ; i<=5; +=i) { }
In simple words: An empty loop is one where the loop's work part (body) has no statements, or is simply represented by empty curly braces. Option (c) shows an empty set of curly braces, making it an empty loop.

๐ŸŽฏ Exam Tip: Look for an isolated semicolon immediately after the loop header, or an empty pair of curly braces, to identify an empty loop.

 

Question 78. A ......... loop is useful for pausing the program for some time.
(a) Finite loop
(b) Infinite loop
Answer: (a) Finite loop
In simple words: A finite loop, which runs a specific number of times, is often used to create a short pause in a program. It keeps the program busy for a set duration without performing a main task.

๐ŸŽฏ Exam Tip: A finite loop, when empty or doing minimal work for many iterations, can act as a simple delay mechanism in programs.

 

Question 79. ................. is a time delay loop.
(a) for(i=1; i<=100; i++);
(b) int i=l; while( ++i < 10) { }
(c) int i=l; do { } while( ++i < 10);
(d) All the options
Answer: (a) for(i=1; i<=100; i++);
In simple words: A `for` loop that runs for a fixed number of times, like `for(i=1; i<=100; i++);`, can be used as a time delay loop. It simply counts without doing any other meaningful work inside its body.

๐ŸŽฏ Exam Tip: Empty loops like `for(;;);` or loops with many iterations and minimal operations are common ways to introduce delays in older programming practices, though modern systems use specific delay functions.

 

Question 80. How many times the following loop will be executed? int i=l; while( ++i < 10) cout<< "The value of i is "<
(a) 10
(b) 9
(c) 8
(d) Infinite times
Answer: (c) 8
In simple words: The loop starts with `i` as 1. The `while(++i < 10)` condition increases `i` before checking, so `i` becomes 2, then 3, and so on, up to 9. When `i` becomes 10, the condition `10 < 10` is false, and the loop stops. This means it prints values from 2 to 9, which are 8 executions.

๐ŸŽฏ Exam Tip: Be careful with pre-increment (`++i`) or post-increment (`i++`) inside loop conditions, as they can change the iteration count by one.

 

Question 81. How many times the following loop will be executed? int i=l; while(i++ < 10) cout<< "The value of i is "<
(a) 10
(b) 9
(c) 8
(d) Infinite times
Answer: (b) 9
In simple words: The loop starts with `i` as 1. The `while(i++ < 10)` condition checks the value of `i` before incrementing it. So it checks 1, 2, 3, up to 9. After checking 9 (<10 is true), `i` becomes 10 and 10 is printed. When `i` becomes 10, it checks `10 < 10` (false), and the loop stops. So, it executes 9 times, printing values from 2 to 10.

๐ŸŽฏ Exam Tip: Understand the difference between pre-increment (`++i`) and post-increment (`i++`) within loop conditions, as it determines whether the value is used before or after being changed.

 

Question 82. In ........... loop, the body of the loop will be executed atleast once.
(a) while
(b) do..while
(c) for
(d) All the options
Answer: (b) do..while
In simple words: In a `do-while` loop, the code inside the loop is always run at least one time. This is because the condition to continue looping is checked at the end of the loop, after the first execution.

๐ŸŽฏ Exam Tip: Use a `do-while` loop when you need to ensure the loop's body is executed at least once, even if the condition is initially false.

 

Question 83. In ........... loop, the body of the loop is executed at least once, even when the condition evaluates false during the first iteration.
(a) for
(b) do..while
(c) for
(d) All the options
Answer: (b) do..while
In simple words: The `do-while` loop is designed to run its code block at least once. This means even if the condition that decides if the loop should continue is false right from the start, the loop's body will still complete its first run.

๐ŸŽฏ Exam Tip: This is a key characteristic of `do-while` loops: they are "exit-controlled" loops, meaning the condition is checked after the body executes.

 

Question 84. What will be the output of the following program? using namespace std; int main () { int n = 10; do { cout<0);
(a) 109 8 7 6 5 43 2 1
(b) 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
(c) 1 2 3 4 5 6 7 8 9 10
(d) 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,0
Answer: (b) 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
In simple words: The program starts with `n` as 10. The `do-while` loop prints `n`, then reduces `n` by 1, and repeats as long as `n` is greater than 0. This will print numbers from 10 down to 1.

๐ŸŽฏ Exam Tip: For `do-while` loops, the body executes first before the condition is checked, so the initial value of `n` (10) will always be printed.

 

Question 85. ................. statements are used to interrupt the normal flow of the program.
(a) Jump
(b) Loop
(c) Decision making
Answer: (a) Jump
In simple words: Jump statements are special commands in a program that can change the normal order in which instructions are followed. They are used to quickly move the program's execution to a different part of the code.

๐ŸŽฏ Exam Tip: Common jump statements include `break`, `continue`, `goto`, and `return`, each serving a specific purpose in altering program flow.

 

Question 86. ................. is a jump statement.
(a) go to statement
(b) break statement
(c) continue statement
(d) All the options
Answer: (d) All the options
In simple words: The `goto`, `break`, and `continue` statements are all examples of jump statements. They are used to change the usual flow of a program's execution.

๐ŸŽฏ Exam Tip: While `goto` is a jump statement, its use is often discouraged in modern programming for making code harder to read and maintain.

 

Question 87. The ................. statement is a control statement which is used to transfer the control from one place to another place without any condition in a program.
(a) go to
(b) break
(c) continue
(d) All the options
Answer: (a) go to
In simple words: The `goto` statement is a control command that can directly move the program's execution from one point to another without needing a specific condition to be met. It provides an unconditional jump.

๐ŸŽฏ Exam Tip: `goto` statements should be used carefully, as they can make programs complex and difficult to understand or debug.

 

Question 88. A ................. statement is a jump statement which terminates the execution of the loop and the control is transferred to resume normal execution after the body of the loop.
(a) go to
(b) break
(c) continue
Answer: (b) break
In simple words: The `break` statement is a jump command that immediately stops the current loop. After leaving the loop, the program continues with the code that comes right after the loop.

๐ŸŽฏ Exam Tip: Use `break` to exit a loop prematurely when a certain condition is met, even if the loop's main condition is still true.

 

Question 89. ................. statement forces the loop to continue or execute the next iteration,
(a) go to
(b) break
(c) continue
(d) All the options statement is executed in
Answer: (c) continue
In simple words: The `continue` statement makes a loop skip the rest of its current cycle and immediately move to the next repetition. It helps to bypass certain parts of the loop's code based on a condition.

๐ŸŽฏ Exam Tip: `continue` is useful for skipping specific iterations of a loop when you don't need to process them, without exiting the entire loop.

 

Question 90. When the ................statement is executed in the loop, the code inside the loop following the .......... statement will be skipped and the next iteration of the loop will begin.
(a) go to
(b) break
(c) continue
(d) All the options
Answer: (c) continue
In simple words: When a `continue` statement is used inside a loop, it tells the program to stop the current loop iteration right there. It then skips any code that comes after it in the loop's body and immediately starts the next iteration of the loop.

๐ŸŽฏ Exam Tip: `continue` helps optimize loops by allowing specific iterations to be shortened or skipped based on intermediate conditions.

 

Question 91. ................. statement breaks the iteration.
(a) continue
(b) break
(c) Both A and B
Answer: (b) break
In simple words: The `break` statement is used to completely stop the execution of a loop. It immediately exits the loop and moves the program control to the statement directly after the loop.

๐ŸŽฏ Exam Tip: `break` effectively "breaks" out of the entire loop structure, while `continue` only skips the current iteration.

 

Question 92. ................. statement skips the iteration.
(a) continue
(b) break
(c) Both A and B
(d) None of these
Answer: (a) continue
In simple words: The `continue` statement causes the program to skip the remaining part of the current loop cycle. It then proceeds to the start of the next iteration, without fully exiting the loop.

๐ŸŽฏ Exam Tip: Remember that `continue` is for skipping *within* a loop iteration, and `break` is for exiting the *entire* loop.

 

Question 93. ................. statement is used with loops as well as switch case.
(a) continue
(b) break
(c) Both A and B
(d) None of these
Answer: (b) break
In simple words: The `break` statement can be used both inside loops (like `for`, `while`, `do-while`) and within `switch` statements. It serves to exit the current structure early.

๐ŸŽฏ Exam Tip: `break` is crucial in `switch` statements to prevent "fall-through" to other `case` blocks after a match.

 

Question 94. ................. statement is only used in loops.
(a) continue
(b) break
(c) Both A and B
Answer: (a) continue
In simple words: The `continue` statement is specifically designed to work only inside loops. Its purpose is to skip the current iteration and move to the next one, which is an operation unique to iterative structures.

๐ŸŽฏ Exam Tip: Unlike `break`, which can be used in both loops and switch statements, `continue` is exclusive to loops.

Very Short Answers (2 Marks)

 

Question 1. What is an if statement? Write its syntax.
Answer: An `if` statement checks a condition. If that condition is true, a specific block of code runs. If the condition is false, that block of code is skipped, and the program moves to the next part. This helps the program make choices and follow different paths based on various inputs or situations. The general syntax of the `if` statement is:
`if (expression)`
`true - block;`
`statement โ€“ x;`
In simple words: An `if` statement helps a computer make decisions. If something is true, it does one thing. If not, it skips that and does something else.

๐ŸŽฏ Exam Tip: To score full marks, define what an `if` statement does, provide its basic syntax, and briefly explain its decision-making role.

 

Question 2. What are the basic control structures?
Answer: The main ways a computer program controls its flow are through selection, iteration, and jump statements. These structures tell the program what to do next. Understanding these three types helps in designing programs that can perform complex tasks by making decisions and repeating actions.
The basics of control structures are:
• Selection statement
• Iteration statement
• Jump statement
In simple words: Control structures are how a program decides what to do. They let it pick choices, repeat things, or jump to a different part.

๐ŸŽฏ Exam Tip: Listing all three main control structures โ€“ selection, iteration, and jump โ€“ is key for this answer.

 

Question 3. What is a computer program?
Answer: A computer program is a collection of instructions that tell a computer what to do. These instructions are written in a specific order to help the computer complete a certain job or task. These instructions are usually written in a programming language that the computer can understand and execute.
In simple words: A computer program is a list of steps that tell a computer how to do a job.

๐ŸŽฏ Exam Tip: Define a computer program as a set of instructions designed to achieve a specific task.

 

Question 4. What is nested if? Mention its types.
Answer: A nested `if` statement is when one `if` statement is placed inside another `if` or `else` statement. This allows for more detailed decision-making. This structure creates a hierarchy of conditions, where an inner condition is only checked if its outer condition is met. The nested `if` can have one of the following three forms:
1. If nested inside `if` part
2. If nested inside `else` part
3. If nested inside both `if` part and `else` part
In simple words: A nested `if` is an `if` statement placed inside another `if` or `else`. It lets you make choices inside other choices.

๐ŸŽฏ Exam Tip: Clearly define nested `if` and list its three possible structural types for full marks.

 

Question 5. What are control statements?
Answer: Control statements are commands that change the normal order of how instructions run in a program. They allow a program to do things one after another, choose between different actions (branching), or repeat actions multiple times. They are fundamental for creating dynamic and functional programs that can respond to different conditions and user inputs. Every programming language provides statements to support sequence, selection (branching), and iteration.
In simple words: Control statements tell a program to change its path. They help it choose, repeat, or skip steps.

๐ŸŽฏ Exam Tip: Focus on explaining that control statements *change the flow* of a program and mention the three main ways they do this: sequence, selection, and iteration.

 

Question 6. What is the exit condition of a loop?
Answer: The exit condition of a loop is the specific rule or test that decides when the loop should stop running. It is also known as the test-condition. The loop continues as long as this condition is true, and stops when it becomes false.
In simple words: The exit condition is the rule that tells a loop when to stop working.

๐ŸŽฏ Exam Tip: Explain that the exit condition (or test condition) dictates when the loop will stop executing.

 

Question 7. What is an iteration or loop?
Answer: An iteration, also called a loop, is when a set of instructions is repeated over and over again. This repetition continues until a specific condition is met, which then causes the loop to stop. Loops are powerful tools for performing repetitive tasks efficiently, such as processing lists of items or counting.
In simple words: A loop means doing the same steps again and again until a certain condition is true.

๐ŸŽฏ Exam Tip: Define iteration as the repetitive execution of statements until a condition is fulfilled.

 

Question 8. What are the advantages of a loop or an iteration?
Answer: Loops or iterations offer several benefits in programming. They help make the code shorter and more compact by avoiding repetitive writing. They also save time during program development and use less computer memory, making programs more efficient. This efficiency is crucial for handling large datasets or performing tasks that require many repeated actions.
In simple words: Loops help make code shorter, save time, and use less memory.

๐ŸŽฏ Exam Tip: Mention at least two key advantages: code reduction and efficiency (time/memory saving).

 

Question 9. What are loop elements?
Answer: Every loop is made up of four main parts, each with its own job. These parts are: the initialization expression (which sets things up at the start), the test expression (which checks if the loop should continue), the update expression (which changes values for the next round), and the body of the loop (which contains the code that gets repeated). Understanding these elements is essential for correctly designing and controlling loop behavior in any programming language.
The four elements are:
1. Initialization expression
2. Test expression
3. Update expression
4. The body of the loop
In simple words: Loops have four parts: starting setup, a check to keep going, an update for the next round, and the main code that repeats.

๐ŸŽฏ Exam Tip: Listing all four elements clearly โ€“ initialization, test, update, and body โ€“ is vital.

 

Question 10. What are the parts of a loop?
Answer: The components of a loop are the same as its elements. These include the initialization, which prepares variables; the test expression, which checks if the loop should continue; the update expression, which modifies variables for the next iteration; and the loop's body, which holds the instructions that are repeatedly executed. These parts work together to ensure that the loop starts correctly, runs for the intended duration, and eventually terminates.
The four parts are:
• Initialization expression
• Test expression
• Update expression
• The body of the loop
In simple words: The parts of a loop are the starting setup, the check to see if it should keep running, the way it updates values, and the code it runs repeatedly.

๐ŸŽฏ Exam Tip: This question is a direct rephrase of Question 9; ensure the same four elements are listed and described concisely.

 

Question 11. Write a note on the declaration of a variable in a for a loop.
Answer: In C++, you can declare a variable directly inside the `for` loop's initialization section. For example, in `for(int i=0; i<=5; ++i)`, the variable `i` is declared and used only within that loop's scope. This is useful for variables that are only needed for the loop itself. Variables declared this way are local to the loop and cannot be accessed from outside it, which helps prevent naming conflicts and improves code organization.
In simple words: You can make a new variable right inside a `for` loop's starting part. This variable only works inside that loop.

๐ŸŽฏ Exam Tip: Emphasize that variables declared in a `for` loop's header have a local scope, meaning they are only valid within that loop.

 

Question 12. Write a program to display numbers from 1 to 10 except 6 using a continue statement.
Answer: This C++ program prints numbers from 1 to 10, but it skips the number 6. It does this by using a `for` loop and an `if` statement with a `continue` command. When `i` is 6, `continue` tells the loop to immediately go to the next number without printing the current one. The `continue` statement is a powerful way to control flow within loops, allowing specific iterations to be conditionally skipped.

#include <iostream>
using namespace std;
int main()
{
for (int i = 1; i <= 10; ++i)
{
if (i == 6)
continue; // Skip printing 6
cout << i << " ";
}
return 0;
}

In simple words: This program shows numbers from 1 to 10. It uses `continue` to jump over the number 6, so 6 is not shown.

๐ŸŽฏ Exam Tip: When asked for a program, provide a complete, compilable code snippet. Ensure the `continue` statement is correctly placed to skip the intended iteration.

 

Question 13. Write about the go-to statement.
Answer: The `goto` statement is a control command that lets a program jump directly from one part of the code to another without any conditions. It simply moves the program's execution to a specific point, marked by a label. The syntax involves using `goto` followed by a `label`, and then the `label` itself followed by a colon where the jump should land. While `goto` offers direct control, its use is often advised against in modern programming as it can make code harder to read, understand, and debug, leading to "spaghetti code."
The syntax of the `goto` statement is:
`goto label;`
`label:`
`statement(s);`
In simple words: The `goto` statement tells the program to immediately jump to a different spot in the code. It does this without checking any rules first.

๐ŸŽฏ Exam Tip: Define `goto` as an unconditional jump statement and provide its basic syntax. It's also good to mention that it's generally discouraged in good programming practice.

 

Question 14. What is a break statement? Explain its working and syntax.
Answer: A `break` statement is a special command that acts as a jump. When a `break` statement is run inside a loop, it immediately stops that loop from continuing. After leaving the loop, the program then goes on to execute the code that comes right after the loop's entire structure. This allows programs to exit loops prematurely based on certain conditions, making the execution more dynamic and efficient.
The general working of a `break` statement with looping statements is:
`for(init; expr 1; expr 2)`
`{`
  `if (condition)`
    `break;`
`}`
`statement;`
In simple words: A `break` statement makes a loop stop right away. The program then moves on to the code that is after the loop.

๐ŸŽฏ Exam Tip: Explain that `break` is a jump statement used to exit a loop or switch statement prematurely, transferring control to the statement immediately following the terminated block.

 

Question 15. Write a note on the continue statement.
Answer: The `continue` statement is used inside loops. When it runs, the loop skips the rest of its current cycle and immediately moves to the next iteration. This means any code after 'continue' within that loop cycle is not executed. It's very useful for skipping certain parts of a loop based on a condition, without stopping the whole loop.
In simple words: The 'continue' statement tells a loop to stop its current action and go straight to the next round. It skips any code that comes after it in the current loop cycle.

๐ŸŽฏ Exam Tip: Remember that 'continue' skips the *current* iteration, while 'break' completely *exits* the loop.

 

Short Answers 3 Marks

 

Question 1. Write a note on the sequence statement.
Answer: A sequence statement refers to instructions in a program that run one after the other, from top to bottom. These statements do not change the normal flow of the program and are always executed in the order they are written. They typically end with a semicolon. This is the most basic way code executes, forming the default execution path in many programming languages.
In simple words: Sequence statements are code lines that run in order, one after the other. They don't skip or repeat; they just do their job from start to finish.

๐ŸŽฏ Exam Tip: Understand that sequential execution is the default, and other control structures like loops or conditions only change this default flow.

 

Question 2. What is a selection statement? Mention its types.
Answer: A selection statement allows a program to choose which code block to execute based on a condition. If the condition is true, one set of statements runs; if false, another set (or nothing) runs. This type of statement is also known as a decision or branching statement because it enables the program to make choices. These statements are essential for creating dynamic programs that can respond differently to various inputs or situations.
Types:
1. Two-way branching
2. Multiway branching
In simple words: Selection statements help a program make decisions. They check a condition, and if it's true, they do one thing; if false, they do something else. The two types are 'two-way' and 'multi-way' branching.

๐ŸŽฏ Exam Tip: Key examples of selection statements are `if`, `if-else`, and `switch` statements.

 

Question 3. Explain the Iteration statement.
Answer: An iteration statement allows a set of instructions to be executed repeatedly, based on a specific condition. As long as the condition remains true, the statements within the loop continue to run. Once the condition becomes false, the repetition stops, and the program moves on. This is commonly known as a looping statement. Loops are incredibly powerful for automating repetitive tasks, like processing every item in a list or performing a calculation multiple times.
In simple words: Iteration statements, or loops, make a computer repeat a set of actions many times. The actions keep repeating as long as a certain condition is true. When the condition becomes false, the loop stops.

๐ŸŽฏ Exam Tip: Remember the three main types of loops: `for`, `while`, and `do-while`, each suited for different scenarios of repetition.

 

Question 4. Explain if statement with syntax and an example.
Answer: An `if` statement checks a condition. If the condition is true, a specific block of code (the 'true-block') is executed. If the condition is false, this block is skipped. The `if` keyword is followed by an expression or condition in parentheses. The `if` statement is a foundational concept in programming, allowing programs to make decisions and follow different paths of execution.
Syntax:
`if (condition)`
`{`
` // true-block statements`
`}`
`// statement-x (executed after if, regardless of condition)`
Example 1: To give a discount if quantity is more than 500.
`if (qty > 500)`
` dis = 10;`
Example 2: To check voting eligibility.
`if (age >= 18)`
` cout << "\n You are eligible for voting ....";`
In simple words: The `if` statement checks if something is true. If it is, a part of the code runs. If not, that part is skipped. For example, if your age is 18 or more, you can vote.

๐ŸŽฏ Exam Tip: Always enclose the condition for an `if` statement in parentheses, and use curly braces `{}` for the code block if it contains more than one statement.

 

Question 5. Explain if..else statement with syntax and an example.
Answer: The `if..else` statement is used to execute one of two possible code blocks based on whether a condition is true or false. First, the condition is evaluated. If it's true, the code within the `if` block runs, and the `else` block is skipped. If the condition is false, the `else` block executes, and the `if` block is skipped. This construct ensures that exactly one of two distinct code paths is always taken, making programs more robust in handling different scenarios.
Syntax:
`if (condition)`
`{`
` // True-block statements`
`}`
`else`
`{`
` // False-block statements`
`}`
Example: To check if a number is even or odd.
`if (num % 2 == 0)`
` cout << "\n The given number is Even";`
`else`
` cout << "\n The given number is Odd";`
In simple words: The `if..else` statement lets a program choose between two actions. If a condition is true, it does the 'if' part. If the condition is false, it does the 'else' part. It's like saying, 'If this happens, do that; otherwise, do this other thing.'

๐ŸŽฏ Exam Tip: Use `if-else` when you have exactly two mutually exclusive outcomes for a decision; for more than two, consider `if-else if-else` or `switch` statements.

 

Question 6. What is a conditional or ternary operator? Explain.
Answer: The conditional operator, also known as the ternary operator, offers a concise way to write `if-else` statements, especially for simple conditions. It uses two symbols, `?` and `:`, and takes three arguments. The first argument is a condition (expression 1). If this condition is true (non-zero), the second argument (expression 2) is evaluated. If the condition is false (zero), the third argument (expression 3) is evaluated. This operator is very useful for assigning a value to a variable based on a condition in a single line, making code shorter and often more readable for simple cases.
Syntax:
`condition ? true_expression : false_expression;`
Example: To find the largest of two numbers `a` and `b`.
`largest = (a > b) ? a : b;`
This means if `a` is greater than `b`, `largest` becomes `a`; otherwise, `largest` becomes `b`.
In simple words: The conditional operator is a short way to write `if-else` for simple choices. It checks a condition using `?` and `:` marks. If the condition is true, it uses the first option; if false, it uses the second. Like asking: 'Is `a` bigger than `b`? If yes, pick `a`; if no, pick `b`.'

๐ŸŽฏ Exam Tip: Use the ternary operator for simple value assignments based on a condition, but avoid it for complex logic to maintain code readability.

 

Question 7. Explain the nested switch statement.
Answer: A nested `switch` statement occurs when one `switch` statement is placed inside another `switch` statement's case block. This allows for more complex decision-making, where an initial choice leads to a secondary choice. Both the inner and outer `switch` statements can have their own case constants and a `default` case. Nested `switch` statements are useful for handling situations where a primary decision branches into secondary, independent choices.
Syntax:
`switch (outer_expression)`
`{`
` case outer_constant_1:`
` // Statements for outer_constant_1`
` switch (inner_expression)`
` {`
` case inner_constant_1:`
` // Statements for inner_constant_1`
` break;`
` case inner_constant_2:`
` // Statements for inner_constant_2`
` break;`
` default:`
` // Default statements for inner switch`
` }`
` break;`
` case outer_constant_2:`
` // Statements for outer_constant_2`
` break;`
` default:`
` // Default statements for outer switch`
`}`
Example Program Walkthrough (Simplified for conciseness):
`int a = 8;`
`switch (a)`
`{`
` case 0:`
` cout << "The number is zero" << endl;`
` break;`
` default:`
` cout << "The number is a non-zero integer" << endl;`
` int b = a % 2; // Calculate remainder for even/odd check`
` switch (b)`
` {`
` case 0:`
` cout << "The number is even" << endl;`
` break;`
` case 1:`
` cout << "The number is odd" << endl;`
` break;`
` }`
`}`
Output:
`The Number is: 8`
`The number is a non-zero integer`
`The number is even`
In simple words: A nested `switch` means putting one `switch` statement inside another one. This helps a program make decisions that have different levels. For example, first, decide if a number is zero, then inside that, decide if it's even or odd.

๐ŸŽฏ Exam Tip: Ensure each `case` within both inner and outer `switch` statements ends with a `break` to prevent fall-through, unless intentional.

 

Question 8. Explain variations of for loop?
Answer: The `for` loop is very flexible and can be used in different ways. One common variation allows for multiple initialization expressions and multiple update expressions, all separated by commas. This means you can set up several variables at the start of the loop and change several variables at the end of each loop cycle. This advanced use of `for` loops is powerful when iterating through data structures that require simultaneous tracking of multiple indices or conditions.
Example:
`#include `
`using namespace std;`
`int main() {`
` int i, j;`
` for (i = 0, j = 10; i < 5; i++, j--) {`
` cout << "Value of i: " << i << ", Value of j: " << j << endl;`
` }`
` return 0;`
`}`
Output:
`Value of i: 0, Value of j: 10`
`Value of i: 1, Value of j: 9`
`Value of i: 2, Value of j: 8`
`Value of i: 3, Value of j: 7`
`Value of i: 4, Value of j: 6`
In simple words: A `for` loop can start and change more than one thing at a time. For example, you can have two counters `i` and `j` that both start at different numbers and change in different ways with each loop cycle. You just separate them with commas.

๐ŸŽฏ Exam Tip: When using multiple expressions, ensure they are logically connected and that the loop's termination condition still functions correctly.

 

Question 9. Explain for loop optional expression with suitable examples.
Answer: A `for` loop usually has three main parts: an initialization, a test condition, and an update expression. However, all these parts are optional, meaning you can leave one or more of them empty if your program design requires it. While optional, carefully managing these expressions is key to avoiding infinite loops or incorrect iteration behavior.
Case 1: Omitting Initialization: You can initialize the loop variable before the `for` loop starts, leaving the initialization part inside the `for` statement empty. The first semicolon is still required.
Example (Case 1):
`#include `
`using namespace std;`
`int main() {`
` int i = 1, sum = 0;`
` // Initialization done outside`
` for (; i <= 10; i++) {`
` sum += i;`
` }`
` cout << "The sum of 1 to 10 is " << sum << endl;`
` return 0;`
`}`
Output (for n=10):
`The sum of 1 to 10 is 55`
Case 2: Omitting Update Expression: You can also perform the update operation inside the loop's body, leaving the update expression part of the `for` statement empty. The second semicolon is still required.
Example (Case 2):
`#include `
`using namespace std;`
`int main() {`
` int i = 1, sum = 0;`
` for (; i <= 10; ) { // Update expression is empty`
` sum += i;`
` i++; // Update done inside the loop body`
` }`
` cout << "The sum of 1 to 10 is " << sum << endl;`
` return 0;`
`}`
Output (for n=10):
`The sum of 1 to 10 is 55`
It's even possible to omit both the initialization and update expressions. If any of these expressions are absent, the control flow is handled by the remaining parts of the loop or by statements outside the `for` loop structure.
In simple words: The `for` loop has three main parts, but you don't have to use all of them. You can set up the starting value before the loop, or change the value inside the loop itself. You just need to keep the semicolons in place inside the `for()` parentheses to show where each part would go.

๐ŸŽฏ Exam Tip: While optional expressions offer flexibility, always ensure that initialization, condition, and update are handled somewhere to prevent infinite loops or unintended behavior.

 

Question 10. What is an empty loop? Give a suitable example.
Answer: An empty loop is a loop that does not contain any statements in its body or has a null statement (just a semicolon) as its body. This means the loop executes its condition and update expressions (if present), but no operations are performed within its block. An infinite loop can be formed if the test expression is missing or always true, causing the loop to run forever. Empty loops are sometimes used for delay or to perform side effects within the loop's control expressions, though this is often considered bad practice for readability.
Example (Empty loop with a null statement):
`for (int i = 0; i <= 5; i++);` // The semicolon after `for(...)` makes its body empty.
Example (Empty loop without explicit semicolon, where the body is meant to be empty):
`int i;`
`for (i = 0; i <= 5; i++) { }` // The empty braces `{}` make its body empty.
In both examples, the loop condition `i <= 5` will be checked and `i` will be incremented. The loop will run 6 times (`i` from 0 to 5) but won't do anything visible because its body is empty.
In simple words: An empty loop is a loop that doesn't do anything inside its main part. It just runs through its cycles and checks its conditions without performing any tasks. Sometimes, it's created by accidentally putting a semicolon after the loop's heading.

๐ŸŽฏ Exam Tip: Be cautious with semicolons after `for` or `while` loop headers; an accidental semicolon can create an empty loop, leading to unexpected program behavior.

 

Question 12. What are the Differences between the Break and Continue statement?
Answer: The `break` and `continue` statements are used to change the normal flow of a program, especially within loops.

Break StatementContinue Statement
It is used to terminate the execution of the loop.It is not used to terminate the execution of the loop.
It stops the iteration.It skips the current iteration.
When this statement is used, control comes out of the loop and executes the statement immediately after the loop.When this statement is used, control does not come out of the loop but moves to the next iteration of the loop.
The `break` statement is used with loops and `switch` cases.The `continue` statement is only used in loops, not in `switch` cases.
In simple words: The `break` statement makes a loop stop completely and immediately. The `continue` statement makes a loop skip just its current turn and move to the next turn.

๐ŸŽฏ Exam Tip: Remember that `break` stops the entire loop, while `continue` only skips the current cycle, allowing the loop to proceed with subsequent iterations.

Book Evaluation

Hands-On Practice

 

Question 1. Write a C++ program to solve the following problems: Temperature โ€“ conversion program that gives the user the option of converting Fahrenheit to Celsius or Celsius to Fahrenheit and depending upon the user's choice.
Answer: This program helps convert temperatures between Fahrenheit and Celsius. It asks the user to choose which conversion they want to do and then performs the calculation.

PROGRAM:
#include<iostream>
using namespace std;
int main()
{
  float f,c;
  int choice;
  cout<<"\n1. Fahrenheit to Celsius";
  cout<<"\n2. Celsius to Fahrenheit";
  cout<<"\n3. Exit";
  cout<<"\nENTER YOUR CHOICE ";
  cin>> choice;
  switch(choice)
  {
    case 1:
      cout<<"\nENTER TEMPERATURE IN FAHRENHEIT ";
      cin>>f;
      c = (f - 32) * 5/9; // Formula to convert Fahrenheit to Celsius
      cout<<"\nTEMPERATURE IN FAHRENHEIT "<<f;
      cout<<"\nTEMPERATURE IN CELSIUS "<<c;
      break;
    case 2:
      cout<<"\nENTER TEMPERATURE IN CELSIUS ";
      cin>>c;
      f = 9*c/5 + 32; // Formula to convert Celsius to Fahrenheit
      cout<<"\nTEMPERATURE IN FAHRENHEIT "<<f;
      cout<<"\nTEMPERATURE IN CELSIUS "<<c;
      break;
    default:
      cout<<"\nPROCESS COMPLETED";
  }
}
Output of the program:
1. Fahrenheit to Celsius
2. Celsius to Fahrenheit
3. Exit
ENTER YOUR CHOICE 1
ENTER TEMPERATURE IN FAHRENHEIT 98
TEMPERATURE IN FAHRENHEIT 98
TEMPERATURE IN CELSIUS 36.6667
1. Fahrenheit to Celsius
2. Celsius to Fahrenheit
3. Exit
ENTER YOUR CHOICE 2
ENTER TEMPERATURE IN CELSIUS 42
TEMPERATURE IN FAHRENHEIT 107.6
TEMPERATURE IN CELSIUS 42
1. Fahrenheit to Celsius
2. Celsius to Fahrenheit
3. Exit
ENTER YOUR CHOICE 3
PROCESS COMPLETED
In simple words: This program lets you pick if you want to change Fahrenheit to Celsius or Celsius to Fahrenheit. You enter your choice and the temperature, and the program gives you the converted value.

๐ŸŽฏ Exam Tip: For conversion programs, always include clear menu options for the user and ensure the conversion formulas are accurate, especially handling integer division if not using floating-point types.

 

Question 2. The program requires the user to enter two numbers and an operator. It then carries out the specified arithmetical operation: addition, subtraction, multiplication, or division of the two numbers. Finally, it displays the result.
Answer: This C++ program acts as a simple calculator. It asks the user for two numbers and an arithmetic operator (+, -, \*, /). Based on the operator, it performs the corresponding calculation and shows the answer.

#include <iostream>
int main()
{
  float num1, num2,result;
  char op;
  cout<<"\n1. Enter two numbers";
  cin>>num1>>num2;
  cout<<"\nEnter operator + or - or * or / : ";
  cin>>op;
  switch(op)
  {
    case'+':
      result = num1 + num2;
      cout<<"\nAdded value "<<result;
      break;
    case'-':
      result = num1 - num2;
      cout<<"\nSubtracted value "<<result;
      break;
    case '*':
      result = num1 * num2;
      cout<<"\nMultiplied value "<<result;
      break;
    case'/':
      result = num1 / num2;
      cout<<"\nDivided value "<<result;
      break;
    default:
      cout<<"\nPROCESS COMPLETED";
  }
}
Output of the program:
1. Enter two numbers 20 12
Enter operator + or - or * or / : +
Added value: 32
1. Enter two numbers 12 10
Enter operator + or - or * or / : -
Subtracted value 2
1. Enter two numbers 12 10
Enter operator + or - or * or / : *
Multiplied value 120
1. Enter two numbers 12 10
Enter operator + or - or * or / : /
Divided value 1.2
In simple words: This program is like a simple calculator. You type in two numbers and then choose if you want to add, subtract, multiply, or divide them. It then gives you the answer.

๐ŸŽฏ Exam Tip: For calculator programs, use a `switch` statement for operator selection and remember to handle division by zero, although this program doesn't explicitly show it.

 

Question 3. Program to input a character and to print whether a given character is an alphabet, digit or any other character.
Answer: This program checks what kind of character a user types. It tells you if the character is a number (digit), a letter (alphabet), or something else entirely.

PROGRAM
#include <iostream>
#include <cctype> // Needed for isdigit() and isalpha()
int main()
{
  char ch;
  cout<<"\n1. Enter a character :";
  cin>>ch;
  if(isdigit(ch)) // Checks if the character is a digit (0-9)
  cout<<"\nThe given character "<<ch<<" is a digit";
  else if(isalpha(ch)) // Checks if the character is an alphabet (a-z, A-Z)
  cout<<"\nThe given character "<<ch<<" is an alphabet";
  else
  cout<<"\nThe given character "<<ch<<" is other character";
}
Output of the program:
1. Enter a character : 7
The given character 7 is a digit
1. Enter a character : y
The given character y is an alphabet
1. Enter a character : &
The given character & is other character
In simple words: The program asks you to type one letter or number. Then, it checks if what you typed is a number, a letter, or a different kind of symbol.

๐ŸŽฏ Exam Tip: Use the `cctype` library functions like `isdigit()` and `isalpha()` for robust character type checking, which makes your code cleaner and more efficient.

 

Question 4. Program to print whether a given character Is an uppercase or a lowercase character or a digit or any other character. Use ASCII codes for it. The ASCII codes are as given below: Characters -ASCII Range '0' โ€“ '9' โ€“ 48 โ€“ 57 'A' โ€“ 'Z' โ€“ 65 โ€“ 90 'a' โ€“ 'z' โ€“ 97 โ€“ 122 other characters 0 โ€“ 255 excluding the above-mentioned codes.
Answer: This program identifies if a character typed by the user is an uppercase letter, a lowercase letter, a digit, or something else. It uses ASCII values, which are special numbers given to each character. Each character has a unique ASCII code, allowing for numerical comparisons.

PROGRAM
#include <iostream>
// No need to include <cctype> as we are using ASCII values for comparison
using namespace std;
int main()
{
  char ch;
  cout<<"\n1. Enter a character: ";
  cin>>ch;
  int av = ch; // 'av' stands for ASCII value, converts character to its ASCII integer
  if(av > 47 && av < 58) // ASCII range for digits '0' to '9'
    cout<<"\nThe given character "<<ch<<" is a digit";
  else if(av > 64 && av < 91) // ASCII range for uppercase 'A' to 'Z'
    cout<<"\nThe given character "<<ch<<" is an Uppercase character";
  else if(av > 96 && av < 123) // ASCII range for lowercase 'a' to 'z'
    cout<<"\nThe given character "<<ch<<" is a Lowercase character";
  else
    cout<<"\nThe given character "<<ch<<" is an Other character";
}
Output of the program:
1. Enter a character : H
The given character H is an Uppercase character
1. Enter a character : u
The given character u is a Lowercase character
1. Enter a character: 7
The given character 7 is a digit
1. Enter a character: &
The given character & is an Other character
In simple words: This program checks if you type a capital letter, a small letter, a number, or another symbol. It does this by looking at a secret number code (ASCII) for each character.

๐ŸŽฏ Exam Tip: When using ASCII values for character classification, ensure you know the correct ranges for digits, uppercase letters, and lowercase letters to avoid errors.

 

Question 5. Program to calculate the factorial of an integer.
Answer: This program calculates the factorial of a number provided by the user. The factorial of a non-negative integer \( n \) is the product of all positive integers less than or equal to \( n \). For example, factorial of 5 (written as 5!) is \( 5 \times 4 \times 3 \times 2 \times 1 = 120 \).

PROGRAM
#include <iostream>
using namespace std;
int main()
{
  int i,n;
  long fact = 1; // Use long for factorial to handle larger numbers
  cout<<"\nEnter a number... ";
  cin>>n;
  for(i=1; i<=n; i++)
  {
    fact = fact * i; // Multiplies 'fact' by 'i' in each iteration
  }
  cout<<"\nFactorial of "<<n<<" is "<<fact;
}
Output of the program:
Enter a number 6
Factorial of 6 is 720
In simple words: You give the program a number, and it figures out its factorial. Factorial means multiplying that number by all the whole numbers smaller than it, down to 1.

๐ŸŽฏ Exam Tip: Remember to initialize the `fact` variable to 1, not 0, otherwise, the product will always be zero. Also, use a `long` data type for `fact` as factorials grow very quickly.

 

Question 6. Program that print 1 2 4 8 16 32 64 128.
Answer: This program prints a series of numbers where each number is double the previous one, starting from 1, up to 128. It demonstrates a simple loop that multiplies a variable by 2 in each step.

PROGRAM
#include <iostream>
using namespace std;
int main()
{
  int i;
  for(i=1; i<=128; i=i*2) // The loop variable 'i' doubles in each iteration
  {
    cout<<i<<"\t"; // Prints the current value of 'i' followed by a tab
  }
}
Output of the program:
1 2 4 8 16 32 64 128
In simple words: This program makes a list of numbers. It starts at 1, then doubles it to get 2, then doubles that to get 4, and keeps going until it reaches 128.

๐ŸŽฏ Exam Tip: For generating sequences, carefully define the loop's initialization, condition, and update expression to ensure it produces the desired pattern and range.

 

Question 7. Program to generate divisors of an integer.
Answer: This program finds all the numbers that can divide a given integer evenly (without leaving a remainder). It takes a number from the user and then checks every number from 1 up to half of the given number to see if it's a divisor. Finally, it also prints the number itself as its largest divisor.

PROGRAM
#include <iostream>
using namespace std;
int main() {
  int n,d;
  cout<<"\n Enter a number...";
  cin>>n;
  cout<<"\nThe divisors for "<<n<<" are ";
  for(d=1; d<=n/2;d++) // Loop from 1 up to half of 'n'
  {
    if(n%d==0) // Checks if 'd' divides 'n' evenly
      cout<<d<<"\t"; // Prints 'd' if it is a divisor
  }
  cout<<n; // 'n' itself is also a divisor
}
Output of the program:
Enter a number 12
The divisors for 12 are 1 2 3 4 6 12
In simple words: You enter a number, and the program finds all the numbers that can divide your number perfectly, without any leftover. It shows you the list of these "divisors."

๐ŸŽฏ Exam Tip: To find divisors efficiently, you only need to check numbers up to \( \text{n}/2 \). The number \( \text{n} \) itself is always a divisor and should be printed separately or included in the loop's upper bound.

 

Question 8. Program to print fibonacci series i.e., 0 1 1 2 3 5 8
Answer:
PROGRAM:
using namespace std;
#include
int main()
{
int n,fl,f2,f3;
fl = -1;
f2 = 1;
cout<<"\nHOW MANY TERMS ... ";
cin>>n;
cout<<"\nTHE FIBONACCI TERMS ARE \n"; for(int i=1; i<=n;i++)
{
f3 = fl+f2;
cout<fl = f2;
f2 = f3;
}
In simple words: This program asks you for a number of terms. Then it calculates and shows the Fibonacci series up to that many terms. Each new number in the series is the sum of the two numbers before it.

๐ŸŽฏ Exam Tip: Remember to initialize the first two Fibonacci numbers correctly, often 0 and 1, to generate the series accurately.

 

Question 9. Programs to produces the following design using nested loops.
Answer:
9. A)
PROGRAM
using namespace std;
#include
int main()
{
int i,j;
for(i=1; i<=6; i++)
{
char c = 'A'; for(j=1;j<=i;j++)
{
cout<C++;
}
cout<<"\n\n";
}
Output:
A
A B
A B C
A B C D
A B C D E
A B C D E F
In simple words: This code uses two loops, one inside the other, to print letters in a pattern. The outer loop controls the rows, and the inner loop prints increasing letters (A, B, C, etc.) in each row. Each row prints one more letter than the row before it.

๐ŸŽฏ Exam Tip: When making patterns with loops, the outer loop usually handles the rows, and the inner loop handles what gets printed in each column of that row.

 

Answer:
9. B)
PROGRAM
using namespace std;
#include
int main()
{
int i,j;
for(i=1; i<=6; i++)
{
char c = 'A'; for(j=1;j<=i;j++)
{
cout<C++;
}
cout<<"\n\n";
}
Output:
A
A B
A B C
A B C D
A B C D E
A B C D E F
In simple words: This program creates a letter pattern using nested loops. The outer loop manages the rows, and the inner loop prints a series of increasing letters for each row. Every new row adds one more letter to the previous one, building a triangle shape.

๐ŸŽฏ Exam Tip: Pay attention to the starting value of the inner loop's counter and how it relates to the outer loop's counter to create specific patterns.

 

Answer:
9.c)
PROGRAM
using namespace std;
#include
int main()
{
int i,j,k=0,m;
for(i=7; i> = 1; i=i-2)
{
for(j=1;j<=i;j++)
cout<<"#\t";
cout<<"\n\n";
k++;
for(m=1;m<=k;m++)
cout<<"\t";
}
Output:
# # # # # # #

# # # # #
        @

# # #
        @        @

#
        @        @        @
In simple words: This program makes a unique pattern using nested loops. It first prints a decreasing number of '#' symbols in rows, then prints a growing number of '@' symbols in new rows, creating two different triangle-like patterns. This shows how multiple loops can combine to form complex designs.

๐ŸŽฏ Exam Tip: Complex patterns often require careful management of multiple nested loops, where each loop controls a specific part of the overall design or character output.

 

Question 10. Program to check whether the square root of a number is a prime or not.
Answer:
PROGRAM
using namespace std;
#include
#include int main()
{
int n,srn,d,p=0;
cout<<"\nENTER A NUMBER ... cin>>n;
srn=sqrt(n);
cout<<"\nTHE GIVEN NUMBER IS "<cout<<"\nTHE SQUARE ROOT OF"<for(d=2; d<=srn/2;d++)
{
if(n%d==0)
{
p=1;
break;
}
}
if(p==0)
cout <<"\nTHE SQUARE ROOT OF THE GIVEN NUMBER "<else
cout <<"\nTHE SQUARE ROOT OF THE GIVEN NUMBER "<}
Output:
ENTER NUMBER: 49
THE GIVEN NUMBER IS 49
THE SQUARE ROOT OF 49 IS 7
THE SQUARE ROOT OF THE GIVEN NUMBER 49 IS A PRIME
ENTER NUMBER: 121
THE GIVEN NUMBER IS 121
THE SQUARE ROOT OF 121 IS 11
THE SQUARE ROOT OF THE GIVEN NUMBER 121 IS A PRIME
ENTER NUMBER: 16
THE GIVEN NUMBER IS 16
THE SQUARE ROOT OF 16 IS 4
THE SQUARE ROOT OF THE GIVEN NUMBER 16 IS NOT A PRIME
In simple words: This program asks for a number, then finds its square root. After that, it checks if this square root is a prime number. A prime number can only be divided evenly by 1 and itself.

๐ŸŽฏ Exam Tip: To check for primality, a common optimization is to only test divisibility up to the square root of the number being checked, which the program does efficiently here.

TN Board Solutions Class 11 Computer Science Chapter 10 Flow of Control

Students can now access the TN Board Solutions for Chapter 10 Flow of Control prepared by teachers on our website. These solutions cover all questions in exercise in your Class 11 Computer Science textbook. Each answer is updated based on the current academic session as per the latest TN Board syllabus.

Detailed Explanations for Chapter 10 Flow of Control

Our expert teachers have provided step-by-step explanations for all the difficult questions in the Class 11 Computer Science chapter. Along with the final answers, we have also explained the concept behind it to help you build stronger understanding of each topic. This will be really helpful for Class 11 students who want to understand both theoretical and practical questions. By studying these TN Board Questions and Answers your basic concepts will improve a lot.

Benefits of using Computer Science Class 11 Solved Papers

Using our Computer Science solutions regularly students will be able to improve their logical thinking and problem-solving speed. These Class 11 solutions are a guide for self-study and homework assistance. Along with the chapter-wise solutions, you should also refer to our Revision Notes and Sample Papers for Chapter 10 Flow of Control to get a complete preparation experience.

FAQs

Where can I find the latest Samacheer Kalvi Class 11 Computer Science Chapter 10 Flow of Control for the 2026-27 session?

The complete and updated Samacheer Kalvi Class 11 Computer Science Chapter 10 Flow of Control is available for free on StudiesToday.com. These solutions for Class 11 Computer Science are as per latest TN Board curriculum.

Are the Computer Science TN Board solutions for Class 11 updated for the new 50% competency-based exam pattern?

Yes, our experts have revised the Samacheer Kalvi Class 11 Computer Science Chapter 10 Flow of Control as per 2026 exam pattern. All textbook exercises have been solved and have added explanation about how the Computer Science concepts are applied in case-study and assertion-reasoning questions.

How do these Class 11 TN Board solutions help in scoring 90% plus marks?

Toppers recommend using TN Board language because TN Board marking schemes are strictly based on textbook definitions. Our Samacheer Kalvi Class 11 Computer Science Chapter 10 Flow of Control will help students to get full marks in the theory paper.

Do you offer Samacheer Kalvi Class 11 Computer Science Chapter 10 Flow of Control in multiple languages like Hindi and English?

Yes, we provide bilingual support for Class 11 Computer Science. You can access Samacheer Kalvi Class 11 Computer Science Chapter 10 Flow of Control in both English and Hindi medium.

Is it possible to download the Computer Science TN Board solutions for Class 11 as a PDF?

Yes, you can download the entire Samacheer Kalvi Class 11 Computer Science Chapter 10 Flow of Control in printable PDF format for offline study on any device.