Official Kerala Board Solutions for Class 11 Computer Science: Chapter 07 Control Statements
Access comprehensive textbook solutions for Chapter 07 Control Statements using the official curriculum guides for Class 11 Computer Science. Designed to align with the 2026-27 Kerala Board standards, these detailed answers help students reinforce core academic concepts.
Chapter-wise Solutions for Computer Science: Chapter 07 Control Statements
Navigate directly to the solved Computer Science textbook exercises using the digital viewer below. Each solution includes detailed step-by-step explanations, allowing students to instantly cross-check their work and identify areas requiring further revision.
One Mark Questions and Answers
Question 1: When an if statement contains another if statement completely, it is known as _________.
Answer:
Nested if
Exam Tips:
a) Remember the term "nested" for any construct placed completely inside another of the same kind (nested if, nested loop, nested switch).
Question 2: Which of the following is not optional in a switch statement?
(a) break
(b) default
(c) case
(d) none of these
Answer:
(c) case
Exam Tips:
a) break and default can be left out, but a switch without any case label has nothing to match, so case is compulsory.
Question 3: To exit from a switch statement, _______ is used.
(a) quit
(b) exit
(c) break
(d) none of these
Answer:
(c) break
Exam Tips:
a) Without break, control "falls through" to the statements of the next case; this is a common mistake in programs.
Question 4: Which of the following statements is true for a switch statement?
(a) switch is used to test the equality
(b) switch is used to test relational or logical expression
(c) switch can handle real numbers case data
(d) none of these
Answer:
(a) switch is used to test the equality
Exam Tips:
a) switch only checks whether the expression is equal to a case constant; relational tests and float values need if-else.
Question 5: Sonet wants to execute a statement more than once. Which of the following is exactly suitable?
(a) if
(b) loop
(c) switch
(d) if else if ladder
Answer:
(b) loop
Exam Tips:
a) Repeating statements is called iteration, and loops (for, while, do-while) are the iteration statements in C++.
Question 6: Odd one out.
(a) for
(b) if
(c) switch
(d) if-else if ladder
Answer:
(a) for. It is a loop, while the others are branching (selection) statements.
Exam Tips:
a) In "odd one out" questions, always give the reason along with the answer; the reason usually carries the mark.
Question 7: Odd one out.
(a) for
(b) if
(c) while
(d) do-while
Answer:
(b) if. It is a branching statement, while the others are loops.
Exam Tips:
a) Group the statements first: selection (if, switch) and iteration (for, while, do-while). The odd one is the one in a different group.
Question 8: Which of the following loops does all three things: initialisation, checking and updation?
(a) while
(b) do-while
(c) for
(d) none of these
Answer:
(c) for
Exam Tips:
a) Only the for loop has places for all three parts inside its own header: for(initialisation; test; update).
Question 9: Predict the output.
for(i = 1; i <= 10; i++);
cout<<i;
(a) 10
(b) 1 to 10
(c) 11
(d) none of these
Answer:
(c) 11. The semicolon after the for statement makes the loop body empty. The loop simply runs until i becomes 11, and then cout<<i; executes once and prints 11.
Exam Tips:
a) A semicolon right after for(...) or while(...) ends the loop there; the next statement runs only once, after the loop.
b) The loop stops when the condition first becomes false, so the value printed is one more than the limit.
Question 10: Which of the following is an exit controlled loop?
(a) for
(b) while
(c) do-while
(d) None of these
Answer:
(c) do-while
Exam Tips:
a) In do-while the condition is checked at the end (exit), so the body runs at least once.
Question 11: _____________ statement is used for an unconditional jump from one location to another.
Answer:
goto
Exam Tips:
a) goto needs a label, written as label_name: before the statement where control should go.
Question 12: Sunitha wants to skip one iteration. Which of the following will help her?
(a) continue
(b) break
(c) for
(d) case
Answer:
(a) continue
Exam Tips:
a) continue skips only the rest of the current iteration; break leaves the loop completely. Do not mix them up.
Question 13: Which of the following is used to terminate a program?
(a) break
(b) continue
(c) end()
(d) exit()
Answer:
(d) exit()
Exam Tips:
a) exit() ends the whole program, while break only ends the loop or switch it is in.
Question 14: Which header file is needed to use the exit() function in a program?
(a) iostream
(b) cstdlib
(c) math
(d) iomanip
Answer:
(b) cstdlib
Exam Tips:
a) Link each function to its header file: exit() - cstdlib, sqrt() - cmath, setw() - iomanip, cout - iostream.
Question 15: In a while loop, where should the loop variable be updated?
(a) along with the while statement
(b) after the while statement
(c) before the while statement
(d) inside the body of while
Answer:
(d) Inside the body of while
Exam Tips:
a) In a while loop, initialisation comes before the loop and updation goes inside the body; only the test is in the while header.
Question 16: How many times will the following loop execute?
int S = 0, i = 0;
do
{
S += i;
i++;
} while(i < 5);
Answer:
5 times (for i = 0, 1, 2, 3 and 4)
Exam Tips:
a) List the values of the loop variable for which the body runs; counting them avoids "off by one" mistakes.
Question 17: 1. _______ statement takes the program control out of the loop even though the test expression is true.
2. Consider the following code fragment. How many times will the character be printed on the screen?
for (i=0; i<10; i=i+2);
cout<<"*";
Answer:
1. break (goto can also be used)
2. Only one time, because of the semicolon (;) at the end of for(i=0; i<10; i=i+2);. The loop has an empty body, and cout<<"*"; runs once after the loop ends.
Exam Tips:
a) break is the expected answer for part 1; it is the standard way to leave a loop early.
b) Always look for a semicolon after the for header before counting iterations.
Question 18: Which selection statement tests the value of a variable or an expression against a list of integer or character constants?
(a) For
(b) If
(c) Switch
(d) Conditional expression
Answer:
(c) switch
Exam Tips:
a) The key phrase is "list of integer or character constants"; these are the case labels of a switch.
Question 19: How many times will the following loop execute?
int m = 2;
do
{
cout<<"Welcome"; m++;
} while (m>10);
Answer:
Only one time
Exam Tips:
a) A do-while loop runs once even if the condition is false at the start, because the test is done after the body.
Question 20: ________ statement takes the program control outside a loop even though the test expression is true.
Answer:
break
Exam Tips:
a) Remember: break - leaves the loop; continue - goes to the next iteration.
Question 21: Read the following C++ statement:
for (int n = 1; n<10; n+=2); cout<<n;
Now choose the correct output from the following options.
(a) 1
(b) 13579
(c) 11
(d) 10
Answer:
(c) 11. The for statement ends with a semicolon, so the loop body is empty. n takes the values 1, 3, 5, 7, 9 and stops at 11. Then cout<<n; executes only once and prints 11.
Exam Tips:
a) Trace the values: 1, 3, 5, 7, 9, 11. The loop stops at the first value that fails n < 10.
b) Option (b) is a trap for students who miss the semicolon.
Question 22: ____________ search method is an example of the 'divide and conquer' method.
Answer:
Binary search
Exam Tips:
a) Binary search repeatedly divides the sorted list into two halves, which is why it is called a divide and conquer method.
Question 23: 1. Name the type of loop which can be used to make sure that the body of the loop is executed at least once.
2. Consider the code given below and predict the output.
for (int i=1; i<=9; i=i+2)
{
if (i==5) continue;
cout<<i<<" ";
}
Answer:
1. do-while loop (exit controlled loop)
2. 1 3 7 9
When i = 5, continue skips the cout statement for that iteration, so 5 is not printed.
Exam Tips:
a) For output questions, write the values of i one by one (1, 3, 5, 7, 9) and strike off the one skipped by continue.
b) Name do-while as an exit controlled loop to make the first answer complete.
Two Mark Questions and Answers
Question 24: Your friend Arun asks you whether there is any loop that does three things: initialisation, testing and updation. What is your answer? Explain.
Answer:
Yes. The for loop is the only loop that does all three things in its header. In the other loops (while and do-while), only the testing is in the loop statement; initialisation must be done before the loop and updation must be done inside the loop body.
The syntax of the for loop is:
for(initialisation; testing; updation)
{
Body of the for loop;
}
Exam Tips:
a) Write the syntax of the for loop; it shows clearly where the three parts appear.
b) Mention where initialisation and updation go in a while loop to show the contrast.
Question 25: While writing a program, Geo uses a while loop but forgets to update the loop variable. What will happen?
Answer:
The loop variable must be updated inside the body of the while loop. If it is not updated, the test condition never becomes false, so the loop never ends. It becomes an infinite loop.
Exam Tips:
a) Use the term "infinite loop" in your answer; it is the key point.
b) You can add that the loop variable must change so that the condition becomes false at some point.
Question 26: Draw the flowchart of the if statement.
Answer:
If the test expression is true, the body of if is executed. If it is false, the body is skipped and control goes to the next statement.
Exam Tips:
a) Use a diamond for the test expression and a rectangle for the body; label the two paths True and False.
b) Both paths must join again below the body of if.
Question 27: Draw the flowchart of the if else statement.
Answer:
If the test expression is true, the body of if is executed; otherwise the body of else is executed. Only one of the two blocks runs.
Exam Tips:
a) Show two separate boxes for the if block and the else block, one on each path of the diamond.
b) Join both paths at the end so the flowchart has a single exit.
Question 28: Write a while loop that displays the numbers from 500 to 550.
Answer:
int i = 500;
while (i<=550)
{
cout<<i<<" ";
i = i + 1;
}
Exam Tips:
a) Initialise before the loop, test in while(), and update inside the body; all three are needed for marks.
b) Use <= 550 so that 550 is also printed.
Question 29: Distinguish between the exit(0) function and the return statement.
Answer:
Both are used to end the program, but they are different:
1. return is a keyword, while exit(0) is a function.
2. return ends the function in which it appears (ending main() ends the program), while exit(0) ends the whole program from anywhere.
3. To use exit(0), the header file cstdlib must be included; return needs no header file.
Exam Tips:
a) Present the differences as numbered points; each correct point earns marks.
b) Do not forget the header file cstdlib for exit().
Question 30: Draw the flowchart of the for loop.
Answer:
The initialisation is done once. Then the test expression is checked. If it is true, the body is executed and the loop variable is updated, and control goes back to the test. When the test becomes false, the loop ends.
Exam Tips:
a) Show the arrow from "update" going back to the test expression; this loop-back arrow is what makes it a loop.
b) Initialisation must be outside the loop path because it is done only once.
Question 31: How many times will the following for loop execute? Justify.
for(i = 0; ; i++)
{
if(i > 5)
cout<<"continue";
else
cout<<"over";
}
Answer:
The loop is infinite. The test condition is missing in the for statement, so it is taken as always true, and nothing inside the body stops the loop.
Exam Tips:
a) An empty test part in a for loop is treated as true; mention this as the justification.
b) The words "continue" and "over" here are only strings being printed, not statements.
Question 32: Predict the output.
#include<iostream>
using namespace std;
int main()
{
int a = 0;
start:
cout<<endl<<++a;
if(a < 5)
goto start;
}
Answer:
1
2
3
4
5
Exam Tips:
a) ++a increases a before printing, so the first value printed is 1, not 0.
b) Check the last value carefully: 5 is printed first and only then is the condition a < 5 tested.
Question 33: for(int i=2, sum=0; i <= 20; i=i+2)
sum += i;
Rewrite the above code using a while loop.
Answer:
int i = 2, sum = 0;
while (i<=20)
{
sum += i;
i = i + 2;
}
Exam Tips:
a) Move the initialisation above the while, keep the test inside while(), and put the update as the last statement of the body.
b) Use braces because the body now has two statements.
Question 34: Rewrite the following code using a switch case statement.
if(day == 1)
cout<<"Sunday";
else if(day == 2)
cout<<"Monday";
else if(day == 7)
cout<<"Saturday";
else
cout<<"Wednesday";
Answer:
switch (day)
{
case 1: cout<<"Sunday"; break;
case 2: cout<<"Monday"; break;
case 7: cout<<"Saturday"; break;
default: cout<<"Wednesday";
}
Exam Tips:
a) The final else becomes the default case.
b) Put break after each case; without it the next cases will also execute.
Question 35: Pick the odd one out from the following. Give reason.
1. for, while, do...while
2. if, switch, for
Answer:
1. do...while. It is an exit controlled loop, while the others are entry controlled loops.
2. for. It is a loop, while the others are branching statements.
Exam Tips:
a) Always write the reason after the odd one; an answer without a reason may get only half the mark.
Question 36: State whether the following statements are True or False. In either case, justify your answer.
1. A break statement is essential in switch.
2. The for loop is an entry controlled loop.
3. The do...while loop is an entry controlled loop.
4. switch is a selection statement.
Answer:
1. False. break is not compulsory in switch. Without break, control simply continues into the next case.
2. True. It checks the condition first, and the body is executed only if the condition is true.
3. False. It is an exit controlled loop; the condition is checked after the body.
4. True. switch selects one block of statements from many, based on the value of an expression.
Exam Tips:
a) The question asks for justification even for True statements; give a one-line reason for each.
b) Remember: for and while are entry controlled; do-while is exit controlled.
Question 37: Write the equivalent code for the following statement.
R = (P<Q ? P : Q);
Answer:
if(P<Q)
R = P;
else
R = Q;
Exam Tips:
a) The part before ? becomes the if condition, the value after ? goes in the if block and the value after : goes in the else block.
Question 38: Examine the following code snippet and find the output. What will happen if the statement int ch; is replaced by char ch;?
int ch;
for(ch='A'; ch<='Z'; ++ch)
cout<<ch<<" ";
Answer:
With int ch;, the code prints the ASCII codes 65 66 67 ... 90.
If int ch; is replaced by char ch;, it prints the letters A B C ... Z.
Exam Tips:
a) Remember that 'A' has the ASCII value 65 and 'Z' has 90.
b) The type of the variable decides whether the number or the character is displayed.
Question 39: 1. _______ is an entry controlled loop.
2. Explain the memory allocation for the following declaration statement.
int A[10][10];
Answer:
1. while loop (or for loop)
2. In GCC (Geany editor), an integer needs 4 bytes. int A[10][10]; has 10 × 10 = 100 elements, so it needs 100 × 4 = 400 bytes.
Exam Tips:
a) Show the working: number of elements × size of one element.
b) Mention the size of int you have assumed (4 bytes in GCC).
Question 40: Differentiate between break and continue statements in C++.
Answer:
break statement:
It is used to exit early from a loop (while, do-while, for) or from a switch. The rest of the loop is skipped completely.
Syntax:
while (expression)
{
if (condition)
break;
}
continue statement:
It skips only the current iteration of the loop and continues the loop with the next iteration.
Syntax:
while (expression)
{
if (condition)
continue;
}
Exam Tips:
a) Give one key line for each: break ends the loop; continue skips one iteration.
b) A syntax or small example for each statement makes the answer complete.
Three Mark Questions and Answers
Question 41: Compare if else and the conditional operator.
Answer:
The conditional operator can be used as an alternative to the if-else statement. It is a ternary operator (it takes three operands).
The syntax of if-else:
if (expression 1)
expression 2;
else
expression 3;
First, expression 1 is evaluated. If it is true, expression 2 is executed; otherwise expression 3 is executed.
The same can be written using the conditional operator as:
expression 1 ? expression 2 : expression 3;
Exam Tips:
a) Write both syntaxes side by side to show how they match.
b) Mention that ?: is a ternary operator; this is a commonly asked point.
c) If-else can hold blocks of statements, while ?: is used for short expressions.
Question 42: #include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter a number in between 1-7";
cin>>n;
switch(n)
{
case 1: cout<<"Sunday"; break;
case 2: cout<<"Monday"; break;
case 3: cout<<"Tuesday"; break;
case 4: cout<<"Wednesday"; break;
case 5: cout<<"Thursday"; break;
case 6: cout<<"Friday"; break;
case 7: cout<<"Saturday"; break;
default: cout<<"Invalid";
}
}
Rewrite the above code using an if else if ladder.
Answer:
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter a number in between 1-7:";
cin>>n;
if(n==1)
cout<<"Sunday";
else if(n==2)
cout<<"Monday";
else if(n==3)
cout<<"Tuesday";
else if(n==4)
cout<<"Wednesday";
else if(n==5)
cout<<"Thursday";
else if(n==6)
cout<<"Friday";
else if(n==7)
cout<<"Saturday";
else
cout<<"Invalid";
}
Exam Tips:
a) Each case value becomes a condition of the form n == value.
b) The default case becomes the final else.
c) break statements are not needed in an if else if ladder.
Question 43: Rewrite the following program using if else.
#include<iostream>
using namespace std;
int main()
{
int a, b, big;
cout<<"Enter two integers";
cin>>a>>b;
big = (a>b) ? a : b;
cout<<"Biggest number is "<<big<<endl;
return 0;
}
Answer:
#include<iostream>
using namespace std;
int main()
{
int a, b, big;
cout<<"Enter two integers";
cin>>a>>b;
if (a>b)
big = a;
else
big = b;
cout<<"Biggest number is "<<big<<endl;
return 0;
}
Exam Tips:
a) Only the line with ?: changes; keep the rest of the program the same.
b) Write complete programs with the header file, using namespace std; and main().
Question 44: #include<iostream>
using namespace std;
int main()
{
int mark;
cout<<"Enter a mark";
cin>>mark;
if(mark>=75)
cout<<"Distinction";
else if (mark>=60)
cout<<"First class";
else if (mark>=50)
cout<<"Second class";
else if (mark>=40)
cout<<"Passed";
else
cout<<"Failed";
}
Is it possible to rewrite the above program using a switch statement? Distinguish between switch and if else if ladder.
Answer:
No. The above code cannot be written using switch, because it checks ranges (mark >= 75 and so on), and switch can test only for equality with constants.
Differences between switch and if else if ladder:
1. switch can test only for equality, but if can evaluate relational or logical expressions.
2. if else is more versatile.
3. if else can handle floating point values, but switch cannot.
4. If the test expression contains more than one variable, if else is used.
5. When a value is tested against a set of constants, switch is more efficient than if else.
Exam Tips:
a) Give the reason for "No" clearly: the conditions are ranges, not single values.
b) Three clear differences are usually enough for a three mark question.
Question 45: Rewrite the following using a nested switch construct.
#include<iostream>
using namespace std;
int main()
{
int a, b;
cout<<"Enter values for a and b";
cin>>a>>b;
if(b==0)
cout<<"Divide by zero error";
else
if (a==0)
cout<<"The result is zero";
else
cout<<"The result is "<<(float)a/b;
}
Answer:
#include<iostream>
using namespace std;
int main()
{
int a, b;
cout<<"Enter values for a and b";
cin>>a>>b;
switch(b)
{
case 0: cout<<"Divide by zero error";
break;
default:
switch(a)
{
case 0: cout<<"The result is zero";
break;
default:
cout<<"The result is "<<(float)a/b;
}
}
}
Exam Tips:
a) The outer if becomes the outer switch and the inner if becomes a switch inside the default of the outer one.
b) Each "== 0" test becomes case 0, and each else becomes default.
c) Close the braces of both switches carefully.
Question 46: Consider the following output and write the code for it.
*
* *
* * *
* * * *
Answer:
#include<iostream>
using namespace std;
int main()
{
int i, j;
for(i=1; i<5; i++)
{
for(j=1; j<=i; j++)
cout<<"* ";
cout<<endl;
}
}
Exam Tips:
a) The outer loop counts the rows and the inner loop prints the stars in each row.
b) Row i has i stars, so the inner loop runs from 1 to i.
c) cout<<endl; must be outside the inner loop but inside the outer loop.
Question 47: Consider the following output and write the code for it.
1
1 2
1 2 3
1 2 3 4
Answer:
#include<iostream>
using namespace std;
int main()
{
int i, j;
for(i=1; i<5; i++)
{
for(j=1; j<=i; j++)
cout<<j<<" ";
cout<<endl;
}
}
Exam Tips:
a) Here the inner loop variable j is printed, so each row starts again from 1.
b) Print a space after each number so the output matches the pattern.
Question 48: Consider the following output and write the code for it.
1
2 2
3 3 3
4 4 4 4
Answer:
#include<iostream>
using namespace std;
int main()
{
int i, j;
for(i=1; i<5; i++)
{
for(j=1; j<=i; j++)
cout<<i<<" ";
cout<<endl;
}
}
Exam Tips:
a) The only change from the previous pattern is printing i (the row number) instead of j.
b) Compare similar patterns to see which variable must be printed.
Question 49: Consider the following output and write the code for it.
1
2 3
4 5 6
7 8 9 10
Answer:
#include<iostream>
using namespace std;
int main()
{
int i, j, k=0;
for(i=1; i<5; i++)
{
for(j=1; j<=i; j++)
cout<<++k<<" ";
cout<<endl;
}
}
Exam Tips:
a) A separate counter k, started at 0 and increased before each print, gives the continuous numbers.
b) Initialise k outside both loops; otherwise it restarts in every row.
Question 50: Consider the following output and write the code for it.
1
1 3
1 3 5
1 3 5 7
Answer:
#include<iostream>
using namespace std;
int main()
{
int i, j;
for(i=1; i<5; i++)
{
for(j=1; j<=i; j++)
cout<<j*2-1<<" ";
cout<<endl;
}
}
Exam Tips:
a) The nth odd number is 2n - 1; use this formula with the inner loop variable.
b) Use * for multiplication in C++, never × or x.
Question 51: Consider the following output and write the code for it.
2
4 4
6 6 6
8 8 8 8
Answer:
#include<iostream>
using namespace std;
int main()
{
int i, j;
for(i=1; i<5; i++)
{
for(j=1; j<=i; j++)
cout<<i*2<<" ";
cout<<endl;
}
}
Exam Tips:
a) Each row prints twice the row number (i*2), repeated i times.
b) Check your code by tracing the first two rows before writing the final answer.
Question 52: Write a program to print the sum of the first n natural numbers.
Answer:
#include<iostream>
using namespace std;
int main()
{
int n, i, sum=0;
cout<<"Enter a value for n";
cin>>n;
for(i=1; i<=n; i++)
{
sum = sum + i;
}
cout<<"The sum of first "<<n<<" numbers is "<<sum;
}
Exam Tips:
a) Initialise sum to 0 before the loop; an uninitialised sum gives a wrong result.
b) Use i <= n so that n itself is added.
c) You can check the result using the formula n(n+1)/2.
Question 53: Write a program to read a number and check whether it is a palindrome or not.
Answer:
#include<iostream>
using namespace std;
int main()
{
int n, m, rem, rev=0;
cout<<"Enter a number";
cin>>n;
m=n;
while(n)
{
rem=n%10;
rev=rev*10+rem;
n=n/10;
}
if(rev==m)
cout<<"The number "<<m<<" is palindrome";
else
cout<<"The number "<<m<<" is not palindrome";
}
Exam Tips:
a) Copy the number into another variable (m = n) before the loop, because n becomes 0 at the end.
b) Learn the three-line digit loop: rem = n%10; rev = rev*10 + rem; n = n/10;. It is used in reverse, palindrome, Armstrong and sum of digits programs.
Question 54: Write a program to print the factorial of a number.
Answer:
#include<iostream>
using namespace std;
int main()
{
int n, i;
long fact = 1;
cout<<"Enter a number";
cin>>n;
for(i=1; i<=n; i++)
fact = fact * i;
cout<<"The factorial of "<<n<<" is "<<fact;
}
Exam Tips:
a) Start fact at 1, not 0; multiplying by 0 always gives 0.
b) long is used because factorials grow very fast.
Question 55: Write a program to print the Fibonacci series.
Answer:
#include<iostream>
using namespace std;
int main()
{
int n, fib1=0, fib2=1, fib3;
cout<<"Enter the limit";
cin>>n;
cout<<"The fibonacci series is ";
if(n==1)
cout<<fib1<<",";
else if(n==2)
cout<<fib1<<","<<fib2<<",";
else if(n>2)
{
cout<<fib1<<","<<fib2<<",";
fib3=fib1+fib2;
while(fib3<=n)
{
cout<<fib3<<",";
fib1=fib2;
fib2=fib3;
fib3=fib1+fib2;
}
}
else
cout<<"Invalid";
}
Exam Tips:
a) Each new term is the sum of the previous two: fib3 = fib1 + fib2, then shift fib1 = fib2 and fib2 = fib3.
b) Print the first two terms 0 and 1 before the loop.
c) Trace the loop for a small limit (say 10) to check that you get 0, 1, 1, 2, 3, 5, 8.
Question 56: Write a program to read a number and check whether it is an Armstrong number or not.
Answer:
#include<iostream>
using namespace std;
int main()
{
int n, m, rem, cube=0;
cout<<"Enter a number";
cin>>n;
m=n;
while(n)
{
rem=n%10;
cube=cube+rem*rem*rem;
n=n/10;
}
if(cube==m)
cout<<"The number "<<m<<" is Armstrong";
else
cout<<"The number "<<m<<" is not Armstrong";
}
Exam Tips:
a) A three-digit Armstrong number equals the sum of the cubes of its digits, e.g. 153 = 1 + 125 + 27.
b) Keep a copy of the original number (m) for the final comparison.
Question 57: Write the code for the following output using a while loop.
*
* *
* * *
* * * *
Answer:
#include<iostream>
using namespace std;
int main()
{
int i, j;
i=1;
while(i<=4)
{
j=1;
while(j<=i)
{
cout<<"* ";
j++;
}
i++;
cout<<endl;
}
}
Exam Tips:
a) Reset j = 1 inside the outer loop before every row; otherwise the inner loop will not run again.
b) Update both i and j inside their loops to avoid infinite loops.
Question 58: Distinguish between an entry controlled loop and an exit controlled loop.
Answer:
An entry controlled loop checks the condition first and enters the body of the loop only if the condition is true.
An exit controlled loop executes the body of the loop once first, even if the condition is false, and then checks the condition.
The for loop and the while loop are entry controlled loops, but the do-while loop is an exit controlled loop.
Exam Tips:
a) Give one example of each type of loop.
b) The key point: an exit controlled loop always runs at least once.
Question 59: Write a program to find the largest of 3 numbers.
Answer:
#include<iostream>
using namespace std;
int main()
{
int a, b, c;
cout<<"Enter three numbers";
cin>>a>>b>>c;
if (a>b && a>c)
cout<<a<<" is large";
else if (b>a && b>c)
cout<<b<<" is large";
else
cout<<c<<" is large";
}
Exam Tips:
a) Use the logical AND operator (&&) to compare one number with both the others.
b) After checking a and b, the remaining case (else) must be c.
Question 60: Write a program to check whether a given number is prime or not.
Answer:
#include<iostream>
using namespace std;
int main()
{
int n, i;
cout<<"Enter a number";
cin>>n;
if(n<2)
{
cout<<n<<" is not a prime no.";
return 0;
}
for(i=2; i<=n/2; i++)
{
if(n%i==0)
{
cout<<n<<" is not a prime no.";
return 0;
}
}
cout<<n<<" is a prime";
}
Exam Tips:
a) A number is prime if no number from 2 to n/2 divides it exactly (n % i == 0).
b) return 0; stops the program as soon as a factor is found, so the "prime" message is not printed.
c) Remember that 1 is not a prime number.
Question 61: Write a program to print the prime numbers less than 100.
Answer:
#include<iostream>
using namespace std;
int main()
{
int i, j=4;
cout<<"The prime numbers less than 100 are given below\n2,3,";
while(j<=100)
{
for(i=2; i<=j/2; i++)
if(j%i==0)
break;
if(i==j/2+1)
cout<<j<<",";
j++;
}
}
Exam Tips:
a) If the inner loop finishes without break, i becomes j/2 + 1; this is how the program knows j is prime.
b) 2 and 3 are printed separately because the test starts from 4.
Question 62: Write a program to read a number and display its factors.
Answer:
#include<iostream>
using namespace std;
int main()
{
int n, i;
cout<<"Enter a number greater than zero";
cin>>n;
cout<<"The factors are ";
for(i=1; i<=n; i++)
if(n%i==0)
cout<<i<<",";
}
Exam Tips:
a) i is a factor of n when n % i == 0.
b) Loop from 1 to n so that both 1 and n are included.
Question 63: Write a program to print the Armstrong numbers less than 1000.
Answer:
#include<iostream>
using namespace std;
int main()
{
int n, i, rem, cube;
for(i=1; i<1000; i++)
{
n=i;
cube=0;
while(n)
{
rem=n%10;
cube=cube+rem*rem*rem;
n=n/10;
}
if(cube==i)
cout<<i<<",";
}
}
Exam Tips:
a) Reset cube to 0 for every new number inside the outer loop.
b) Work on a copy (n = i) so that the loop variable i is not destroyed.
c) The output should be 1, 153, 370, 371, 407; use it to check your program.
Question 64: char result;
float marks;
cin>>marks;
if (marks >= 50)
result = 'P';
else
result = 'F';
cout<<result;
Rewrite the above code without using the if statement.
Answer:
char result;
float marks;
cin>>marks;
result = (marks>=50) ? 'P' : 'F';
cout<<result;
Exam Tips:
a) Use the conditional operator ?: as the replacement for a simple if-else.
b) Character constants are written in single quotes, like 'P'.
Question 65: The output of a program is given below.
1
3
5
7
9
The sum is 25
Write a C++ program to obtain the above output.
Answer:
#include<iostream>
using namespace std;
int main()
{
int sum=0, i;
for (i=1; i<=9; i+=2)
{
cout<<i<<endl;
sum = sum + i;
}
cout<<"The sum is "<<sum;
}
Exam Tips:
a) Increase i by 2 (i += 2) to get odd numbers.
b) Print each number and add it to sum inside the same loop.
Question 66: Find the errors in syntax, if any, and correct them.
1. while (test condition);
{
}
2. do (condition)
{
}while
3. switch (condition)
{
Case 1:
Case 2:
Case 3:
Case 4:
}
Answer:
1. There should be no semicolon after while (test condition). The corrected loop is:
while (test condition)
{
}
2. In a do...while loop, the condition is written after while (not after do), and while must end with a semicolon:
do
{
}while (condition);
3. switch takes an expression (whose value is compared with the cases), not a condition, and the keyword case must be in lowercase:
switch (expression)
{
case 1:
case 2:
case 3:
case 4:
}
Exam Tips:
a) C++ keywords are case sensitive; Case or While are errors.
b) Remember that do-while is the only loop that ends with a semicolon after the condition.
c) For each error, state the mistake and then write the corrected code.
Question 67: Given the total mark of each student in the SSLC examination, write a C++ code fragment to find the grades.
Answer:
#include<iostream>
using namespace std;
int main()
{
int mark;
cout<<"Enter total mark";
cin>>mark;
if (mark>100 || mark<0)
cout<<"Invalid mark";
else
{
if (mark>=90)
cout<<"Your grade is A+";
else if (mark>=80)
cout<<"Your grade is A";
else if (mark>=70)
cout<<"Your grade is B+";
else if (mark>=60)
cout<<"Your grade is B";
else if (mark>=50)
cout<<"Your grade is C+";
else if (mark>=40)
cout<<"Your grade is C";
else if (mark>=30)
cout<<"Your grade is D+";
else
cout<<"Your grade is D";
}
}
Exam Tips:
a) Check the highest range first in an else if ladder; otherwise a high mark may match a lower grade.
b) Rejecting marks outside 0-100 shows good validation and is a good habit.
Question 68: You are given the heights of 3 students. Write the relevant code segment to find the maximum height.
Answer:
#include<iostream>
using namespace std;
int main()
{
int h1, h2, h3, max;
cout<<"Enter height1:";
cin>>h1;
cout<<"Enter height2:";
cin>>h2;
cout<<"Enter height3:";
cin>>h3;
if(h1>h2 && h1>h3)
max=h1;
else if(h2>h1 && h2>h3)
max=h2;
else
max=h3;
cout<<"The maximum height is "<<max;
}
Exam Tips:
a) This is the same logic as finding the largest of three numbers; only the variable names change.
b) Store the result in a variable (max) and print it once at the end.
Question 69: Write the easiest code snippet for printing your name 1000 times. Explain.
Answer:
#include<iostream>
using namespace std;
int main()
{
int i;
char name[20];
cout<<"Enter your name:";
cin>>name;
for(i=0; i<1000; i++)
cout<<name<<endl;
}
A for loop is the easiest way. The name is read once, and the loop runs 1000 times (i = 0 to 999), printing the name each time.
Exam Tips:
a) Starting from 0 with i < 1000 gives exactly 1000 repetitions.
b) The question says "Explain", so add one or two lines about how the loop works.
Question 70: Given the code segment:
for(i=1; i<10; i++)
cout<<i;
1. Rewrite the code using a do...while loop.
2. What will be the output when i = 0? Give reason.
Answer:
1.
i = 1;
do
{
cout<<i; i++;
}while(i<10);
2. If i starts from 0, the loop runs one more time and prints 0123456789. The for loop starting from 1 executes 9 times, but starting from 0 it executes 10 times.
Exam Tips:
a) In do...while, initialise before do and put the condition after while, ending with a semicolon.
b) Show the actual output when asked to predict, not just the number of times.
Question 71: Whenever a string is entered, the reverse of that string is displayed (e.g. if we enter 'CAR', the output is 'RAC'). Write a suitable program for this.
Answer:
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int i, len;
char str[80];
cout<<"Enter a string :";
cin.getline(str, 80);
len=strlen(str);
for(i=len-1; i>=0; i--)
cout<<str[i];
}
Exam Tips:
a) The last character of the string is at position len - 1, so the loop starts there and moves back to 0.
b) Include cstring for strlen().
Question 72: Write a C++ program to display the following.
A
A B
A B C
A B C D
A B C D E
Answer:
#include<iostream>
using namespace std;
int main()
{
char i, j;
for(i='A'; i<'F'; i++)
{
for(j='A'; j<=i; j++)
cout<<j<<"\t";
cout<<endl;
}
}
OR
#include<iostream>
using namespace std;
int main()
{
int i, j;
for(i=65; i<70; i++)
{
for(j=65; j<=i; j++)
cout<<(char)j<<"\t";
cout<<endl;
}
}
Exam Tips:
a) A char variable can be used as a loop variable, because characters are stored as ASCII codes.
b) When an int is used, convert it with (char) to print letters instead of numbers.
Question 73: 1. Write a C++ program to get the following output.
1
1 2
1 2 3
1 2 3 4
OR
2. Consider the following C++ program and answer the questions.
#include<iostream>
using namespace std;
int main()
{
int a, p = 1;
for(a=1; a<=5; a+=2)
p = p * a;
cout<<p;
}
(a) Predict the output of the above code.
(b) Rewrite the above program using a while loop.
Answer:
1.
#include<iostream>
using namespace std;
int main()
{
int i, j;
for(i=1; i<=4; i++)
{
for(j=1; j<=i; j++)
cout<<j<<"\t";
cout<<"\n";
}
}
2.
(a) The output is 15 (p = 1 × 1 × 3 × 5).
(b)
#include<iostream>
using namespace std;
int main()
{
int a=1, p=1;
while(a<=5)
{
p=p*a;
a+=2;
}
cout<<p;
}
Exam Tips:
a) For (a), trace a = 1, 3, 5 and multiply; writing the trace shows the working.
b) When changing for to while, move a=1 above the loop and a+=2 inside the body.
Five Mark Questions and Answers
Question 74: "We know that the execution of a program is sequential." Is it possible to change this sequential manner? Explain the different jump statements in detail.
Answer:
Yes. The execution of a program is sequential, but we can change this order using jump statements. The jump statements are:
1. goto statement:
Using goto, we can transfer control to any place in the program without any condition. The syntax is goto label;
Example:
#include<iostream>
using namespace std;
int main()
{
float a, b;
cout<<"Enter 2 numbers";
cin>>a>>b;
if(b==0)
goto end;
cout<<"The quotient is "<<a/b;
return 0;
end: cout<<"Division by zero error";
}
2. break statement:
It is used to exit early from a loop such as while, do-while or for, or from a switch.
Syntax:
while (expression)
{
if (condition)
break;
}
Example:
#include<iostream>
using namespace std;
int main()
{
int i=1;
while(i<10)
{
cout<<i<<endl;
if(i==5)
break;
i++;
}
}
The output is
1
2
3
4
5
3. continue statement:
It skips one iteration of the loop and continues with the next iteration.
Syntax:
while (expression)
{
if (condition)
continue;
}
Example:
#include<iostream>
using namespace std;
int main()
{
int i=0;
while(i<10)
{
i++;
if(i==5) continue;
cout<<i<<endl;
}
}
The output is
1
2
3
4
6
7
8
9
10
4. exit(0) function:
It is used to terminate the program. For this, the header file cstdlib must be included.
Exam Tips:
a) Name all four (goto, break, continue, exit()) before explaining them; each one with syntax and example earns marks.
b) In examples, show the output so the effect of the jump is clear.
c) Remember exit() needs the cstdlib header file.
Question 75: Mr. X wants to get the output 9 when he inputs 342, and 12 when he inputs 651. Write the program and draw a suitable flowchart for X.
Answer:
Here the output is the sum of the digits of the number (3 + 4 + 2 = 9 and 6 + 5 + 1 = 12).
Flowchart:
Program:
#include<iostream>
using namespace std;
int main()
{
int n, rem, sum=0;
cout<<"Enter a number";
cin>>n;
while(n)
{
rem=n%10;
sum=sum+rem;
n=n/10;
}
cout<<"The sum of digits is "<<sum;
}
Exam Tips:
a) First identify the logic from the examples (sum of digits) and state it in one line.
b) Use the standard shapes: oval for start/stop, parallelogram for input/output, diamond for decision, rectangle for process.
c) Make sure the flowchart steps match the program steps.
Question 76: Explain the conditional statements in detail.
Answer:
1. Simple if:
The syntax is:
if(expression)
statement;
or
if(expression)
{
Block of statements
}
First the expression is evaluated. Only if it is true is the statement executed.
eg: if (n>0)
cout<<n<<" is positive";
2. if else:
The syntax is:
if (expression)
statement 1;
else
statement 2;
or
if (expression)
{
statement block 1;
}
else
{
statement block 2;
}
First the expression is evaluated. If it is true, statement block 1 is executed; otherwise statement block 2 is executed. Only one block is executed at a time, so it is called a branching statement.
eg:
if (n>0)
cout<<n<<" is positive";
else
cout<<n<<" is negative";
3. if else if ladder:
The syntax is:
if (expression 1)
{
statement block 1;
}
else if (expression 2)
{
statement block 2;
}
else if (expression 3)
{
statement block 3;
}
else
{
statement block n;
}
First expression 1 is evaluated. If it is true, only statement block 1 is executed. Otherwise expression 2 is evaluated, and if it is true, only statement block 2 is executed, and so on. If all the expressions are false, statement block n is executed.
eg:
if (mark>=90)
cout<<"Your grade is A+";
else if (mark>=80)
cout<<"Your grade is A";
else if (mark>=70)
cout<<"Your grade is B+";
else if (mark>=60)
cout<<"Your grade is B";
else if (mark>=50)
cout<<"Your grade is C+";
else if (mark>=40)
cout<<"Your grade is C";
else if (mark>=30)
cout<<"Your grade is D+";
else
cout<<"Your grade is D";
4. Conditional operator:
It is a ternary operator and an alternative to the if else construct. The syntax is:
expression 1 ? expression 2 : expression 3;
or
expression 1 ? value if true : value if false;
First expression 1 is evaluated. If it is true, expression 2 is executed; otherwise expression 3 is executed.
eg:
n>0 ? cout<<n<<" is positive" : cout<<n<<" is negative";
5. switch:
It is a multiple branch statement. The syntax is:
switch(expression)
{
case value: statements; break;
case value: statements; break;
case value: statements; break;
......
default: statements;
}
First the expression is evaluated, and the statements of the matching case value are executed. If no case matches, the default statements are executed.
eg:
switch (n)
{
case 1: cout<<"Sunday"; break;
case 2: cout<<"Monday"; break;
case 3: cout<<"Tuesday"; break;
case 4: cout<<"Wednesday"; break;
case 5: cout<<"Thursday"; break;
case 6: cout<<"Friday"; break;
case 7: cout<<"Saturday"; break;
default: cout<<"Invalid";
}
Exam Tips:
a) For each statement, give the syntax, a one-line working and a small example; this is what a five mark answer needs.
b) Mention that the conditional operator is a ternary operator and switch tests only equality.
c) Write keywords in lowercase (if, else, switch, case); If or Case would be errors.
Question 77: Explain the different loops in detail.
Answer:
1. for loop:
The syntax of the for loop is:
for(initialisation; checking; update loop variable)
{
Body of loop;
}
The initialisation part is executed only once. Then the condition is checked. If it is true, the body of the loop is executed. Then the loop variable is updated and the condition is checked again. This continues until the condition becomes false. It is an entry controlled loop.
eg: for(i=1, j=1; i<=10; i++, j++)
cout<<i<<" x "<<j<<" = "<<i*j<<endl;
2. while loop:
It is also an entry controlled loop. The syntax is:
loop variable initialised;
while(expression)
{
Body of the loop;
Update loop variable;
}
Here the loop variable must be initialised before the while loop. Then the expression is evaluated, and only if it is true is the body of the loop executed. The loop variable must be updated inside the body. The body is executed repeatedly until the expression becomes false.
eg:
i = 1;
j = 1;
while(i<=10)
{
cout<<i<<" x "<<j<<" = "<<i*j<<endl;
i++;
j++;
}
3. do while loop:
It is an exit controlled loop. The syntax is:
do
{
Statements
}while(expression);
Here the body is executed at least once, even if the condition is false. After executing the body, the expression is checked. If it is false, the loop ends; otherwise the body is executed again.
eg:
i = 1;
do
{
cout<<i<<endl;
i++;
}while(i<=10);
Exam Tips:
a) For each loop, write the syntax, explain the order of steps and give an example.
b) Clearly state which loops are entry controlled (for, while) and which is exit controlled (do while).
c) Use * for multiplication in code; × is not a C++ operator.
Question 78: 1. Write a program to do the following:
a) Input the values for the variables 'n' and 'm'.
b) Print the numbers between 'm' and 'n' which are exactly divisible by 'm'.
c) Check whether the numbers divisible by 'm' are odd or even.
2. Write a program using a nested loop that inputs a number 'n' and generates an output as follows (if the value of 'n' is 5):
25
25 16
25 16 9
25 16 9 4
25 16 9 4 1
Answer:
1.
#include<iostream>
using namespace std;
int main()
{
int i, n, m;
cout<<"Enter values for n and m";
cin>>n>>m;
for(i=m; i<=n; i++)
if(i%m == 0)
{
cout<<i<<"\t";
if(i%2 == 0)
cout<<"even"<<endl;
else
cout<<"odd"<<endl;
}
}
2.
#include<iostream>
using namespace std;
int main()
{
int n, i, j;
cout<<"Enter a value for n:";
cin>>n;
for(i=n; i>0; i--)
{
for(j=n; j>=i; j--)
cout<<j*j<<"\t";
cout<<endl;
}
}
Exam Tips:
a) The first program covers all three parts (input, divisible check, odd/even check) in one loop.
b) In the pattern, each row starts from n and goes down to i; print j*j for the squares.
c) Use standard C++ (iostream, using namespace std;, int main()) in exams.
Question 79: Write a C++ program to display the Fibonacci series.
Answer:
#include<iostream>
using namespace std;
int main()
{
int n, fib1=0, fib2=1, fib3;
cout<<"Enter the limit";
cin>>n;
cout<<"The fibonacci series is ";
if(n==1)
cout<<fib1<<",";
else if(n==2)
cout<<fib1<<","<<fib2<<",";
else if (n>2)
{
cout<<fib1<<","<<fib2<<",";
fib3=fib1+fib2;
while(fib3<=n)
{
cout<<fib3<<",";
fib1=fib2;
fib2=fib3;
fib3=fib1+fib2;
}
}
else
cout<<"Invalid";
}
Exam Tips:
a) Explain the idea in one line: every term after the first two is the sum of the previous two terms.
b) Show the shifting of values (fib1 = fib2; fib2 = fib3;) clearly; this is the step students usually miss.
c) Write a sample output, e.g. for limit 20: 0, 1, 1, 2, 3, 5, 8, 13.
Question 80: 1. Write a C++ program to accept an integer and check whether it is an Armstrong number or not. (Hint: The sum of the cubes of the digits of an Armstrong number is equal to the number itself.)
2. Write a C++ program to accept an integer and print its reverse. (Hint: If 234 is given, the output must be 432.)
Answer:
1.
#include<iostream>
using namespace std;
int main()
{
int n, m, rem, cube=0;
cout<<"Enter a number";
cin>>n;
m=n;
while(n)
{
rem=n%10;
cube=cube+rem*rem*rem;
n=n/10;
}
if(cube==m)
cout<<"The number "<<m<<" is Armstrong";
else
cout<<"The number "<<m<<" is not Armstrong";
}
2.
#include<iostream>
using namespace std;
int main()
{
int n, rem, rev = 0;
cout<<"Enter a number:";
cin>>n;
while (n)
{
rem = n%10;
rev = rev*10+rem;
n = n/10;
}
cout<<"The reverse is "<<rev;
}
Exam Tips:
a) Both programs use the same digit-extraction loop (n%10 and n/10); only the calculation inside changes.
b) For the Armstrong check, save the original number before the loop.
c) Trace 234 through the reverse loop (rev = 4, 43, 432) to check your answer.
Question 81: 1. Write a menu driven program which accepts 3 numbers and shows options to find and display:
the biggest number
the smallest number
the sum of the numbers
the product of the numbers
2. Write a C++ program to check whether a number is a palindrome or not.
Answer:
1.
#include<iostream>
using namespace std;
int big (int n1, int n2, int n3)
{
if (n1>n2 && n1>n3)
return n1;
else if (n2>n1 && n2>n3)
return n2;
else
return n3;
}
int small (int n1, int n2, int n3)
{
if (n1<n2 && n1<n3)
return n1;
else if (n2<n1 && n2<n3)
return n2;
else
return n3;
}
int sum (int n1, int n2, int n3)
{
return (n1+n2+n3);
}
int prod (int n1, int n2, int n3)
{
return (n1*n2*n3);
}
int main()
{
int x, y, z, ch;
cout<<"Enter 3 nos";
cin>>x>>y>>z;
cout<<"Enter 1 for the biggest number";
cout<<"\n2 for the smallest number";
cout<<"\n3 for the sum of numbers";
cout<<"\n4 for the product of numbers";
cout<<"\nEnter your choice:";
cin>>ch;
switch (ch)
{
case 1: cout<<"The biggest number is "<<big(x,y,z);
break;
case 2: cout<<"The smallest number is "<<small(x,y,z);
break;
case 3: cout<<"The sum of numbers is "<<sum(x,y,z);
break;
case 4: cout<<"The product is "<<prod(x,y,z);
break;
default: cout<<"Invalid choice";
}
}
2.
#include<iostream>
using namespace std;
int main()
{
int n, m, rem, rev=0;
cout<<"Enter a number";
cin>>n;
m=n;
while(n)
{
rem=n%10;
rev=rev*10+rem;
n=n/10;
}
if(rev==m)
cout<<"The number "<<m<<" is palindrome";
else
cout<<"The number "<<m<<" is not palindrome";
}
Exam Tips:
a) A menu driven program displays the choices, reads the choice and uses switch to perform the selected task.
b) Check that each case calls the correct function; a wrong call gives a wrong result even if the program compiles.
c) Include a default case for invalid choices.
Question 82: 1. Write a C++ program to display all leap years between 1000 and 2000, excluding all century years.
2. Write a C++ program to find the sum of the first 10 numbers of the Fibonacci series. (The Fibonacci series is 0, 1, 1, 2, 3, 5, 8, 13, ... where 0 and 1 are the first two terms and the remaining terms are obtained by adding the two preceding terms.)
Answer:
1.
#include<iostream>
using namespace std;
int main()
{
int i;
cout<<"Leap years between 1000 and 2000 are given below\n";
for (i=1000; i<=2000; i++)
{
if (i%100 != 0 && i%4 == 0)
cout<<i<<", ";
}
}
2.
#include<iostream>
using namespace std;
int main()
{
int i, fib1 = 0, fib2 = 1, fib3, S;
S = fib1 + fib2;
for (i = 1; i <= 8; i++)
{
fib3 = fib1 + fib2;
S = S + fib3;
fib1 = fib2;
fib2 = fib3;
}
cout<<"The sum of first 10 numbers of Fibonacci series is "<<S;
}
The sum is 0 + 1 + 1 + 2 + 3 + 5 + 8 + 13 + 21 + 34 = 88.
Exam Tips:
a) Read the question carefully: "excluding all century years" means any year divisible by 100 must be skipped.
b) The first two terms are added before the loop, so the loop runs only 8 times for 10 terms.
c) Calculate the expected answer (88) by hand to check your program.
Question 83: 1. Write a program to check whether the given number is a palindrome or not.
OR
2. Write a program to print the leap years between 2000 and 3000. (A century year is a leap year only if it is divisible by 400, and a non-century year is a leap year only if it is divisible by 4.)
Answer:
1.
#include<iostream>
using namespace std;
int main()
{
int n, m, rem, rev=0;
cout<<"Enter a number";
cin>>n;
m=n;
while(n)
{
rem=n%10;
rev=rev*10+rem;
n=n/10;
}
if(rev==m)
cout<<"The number "<<m<<" is palindrome";
else
cout<<"The number "<<m<<" is not palindrome";
}
2.
#include<iostream>
using namespace std;
int main()
{
int year;
for(year=2000; year<=3000; year++)
{
if(year%100==0)
{
if(year%400==0)
cout<<year<<endl;
}
else
{
if(year%4==0)
cout<<year<<endl;
}
}
}
Exam Tips:
a) For leap years, test the century condition (year % 100 == 0) first, then use % 400 for century years and % 4 for others.
b) In this range, 2000 is a leap year but 2100, 2200, 2300, 2500, 2600, 2700, 2900 and 3000 are not.
c) A palindrome reads the same in reverse, e.g. 121; compare the reversed number with the original copy.
Free study material for Computer Science
Computer Science Class 11 Curriculum Solutions: Chapter 07 Control Statements
Accessing Chapter 07 Control Statements Solutions
Access structured Kerala Board textbook solutions for Chapter 07 Control Statements. Designed in alignment with the latest academic curriculum for Class 11 Computer Science, these answers cover all end-of-chapter exercises to support daily learning and homework completion.
Concept-Driven Answers for Class 11 Computer Science
Beyond providing final answers, these guides offer step-by-step breakdowns for complex queries in the Class 11 Computer Science module. This approach helps students balance theoretical depth with practical problem-solving skills required for Kerala Board exams.
Maximizing Study Efficiency
These resources act as an effective roadmap for daily homework tasks and independent study. Supplement your review of Chapter 07 Control Statements with official sample papers and interactive practice tests available on our platform free of charge.
FAQs
The complete and updated Kerala Plus One Computer Science Chapter 7 Control Statements Questions and Answers is available for free on StudiesToday.com. These solutions for Class 11 Computer Science are as per latest Kerala Board curriculum.
Yes, our experts have revised the Kerala Plus One Computer Science Chapter 7 Control Statements Questions and Answers 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.
Toppers recommend using Kerala Board language because Kerala Board marking schemes are strictly based on textbook definitions. Our Kerala Plus One Computer Science Chapter 7 Control Statements Questions and Answers will help students to get full marks in the theory paper.
Yes, we provide bilingual support for Class 11 Computer Science. You can access Kerala Plus One Computer Science Chapter 7 Control Statements Questions and Answers in both English and Hindi medium.
Yes, you can download the entire Kerala Plus One Computer Science Chapter 7 Control Statements Questions and Answers in printable PDF format for offline study on any device.