Skip to main content
Chapter 6 of 11
NCERT Solutions

Flow of Control

Assam Board · Class 11 · Computer Science

NCERT Solutions for Flow of Control — Assam Board Class 11 Computer Science.

30 questions25 flashcards5 concepts

Interactive on Super Tutor

Studying Flow of Control? Get the full interactive chapter.

Quizzes, flashcards, AI doubt-solver and a step-by-step study plan — built for ncert solutions and more.

1,000+ Class 11 students started this chapter today

16 Questions Solved · 3 Sections

EXERCISE

1What is the difference between else and elif construct of if statement?Show solution
Given: Two constructs of the `if` statement — `else` and `elif`.

Concept: Both are used with the `if` statement for decision making, but they serve different purposes.

| Feature | `else` | `elif` |
|---|---|---|
| Full form | else | else if |
| Condition | Does not take any condition | Takes a condition to test |
| Purpose | Executes when the `if` (and all preceding `elif`) conditions are False | Executes when its own condition is True and all previous conditions are False |
| Number of times used | Only once at the end of an if block | Can be used multiple times |
| Alternative | Provides a single alternative | Provides multiple alternatives |

Example:
```python
# Using else
x = 5
if x > 10:
print("Greater than 10")
else:
print("Not greater than 10") # This executes

# Using elif
marks = 75
if marks >= 90:
print("Grade A")
elif marks >= 75:
print("Grade B") # This executes
elif marks >= 60:
print("Grade C")
else:
print("Grade D")
```

Conclusion: `else` provides one alternative when the `if` condition is False, whereas `elif` allows checking multiple conditions in sequence.
2What is the purpose of range() function? Give one example.Show solution
Purpose of `range()` function:

The `range()` function is used to generate a sequence of integers. It is commonly used with the `for` loop to repeat a block of code a specific number of times.

Syntax:
range(start, stop, step)\text{range(start, stop, step)}

- `start` — Starting value of the sequence (default is 0)
- `stop` — The sequence goes up to `stop - 1` (this value is not included)
- `step` — Difference between each number in the sequence (default is 1)

Example:
```python
for i in range(1, 10, 2):
print(i)
```

Output:
```
1
3
5
7
9
```

Explanation: The `range(1, 10, 2)` generates the sequence 1,3,5,7,91, 3, 5, 7, 9 — starting from 1, ending before 10, with a step of 2. The `for` loop iterates over each value in this sequence.
3Differentiate between break and continue statements using examples.Show solution
Given: Two loop control statements — `break` and `continue`.

Difference:

| Feature | `break` | `continue` |
|---|---|---|
| Purpose | Terminates the loop immediately | Skips the current iteration and moves to the next |
| Control flow | Exits the loop entirely; execution continues with the statement after the loop | Jumps back to the beginning of the loop for the next iteration |
| Remaining iterations | All remaining iterations are skipped | Remaining iterations continue to execute |

Example of `break`:
```python
for i in range(1, 6):
if i == 3:
break
print(i)
```
Output:
```
1
2
```
*Explanation:* When `i` becomes 3, the `break` statement exits the loop. Values 3, 4, 5 are never printed.

Example of `continue`:
```python
for i in range(1, 6):
if i == 3:
continue
print(i)
```
Output:
```
1
2
4
5
```
*Explanation:* When `i` becomes 3, the `continue` statement skips the `print` for that iteration and moves to `i = 4`. All other values are printed normally.
4What is an infinite loop? Give one example.Show solution
Definition:
An infinite loop is a loop that never terminates because its loop condition always remains `True` and never becomes `False`. This is a logical error in the program. The statements within the body of the loop must ensure that the condition eventually becomes False; if they do not, the loop runs forever.

Cause: Usually occurs when the loop variable is not updated correctly inside the loop body.

Example:
```python
i = 1
while i > 0:
print(i)
i = i + 1 # i keeps increasing, condition i > 0 is always True
```

Explanation:
- Initially `i = 1`, so the condition `i > 0` is `True`.
- Inside the loop, `i` is incremented by 1 each time.
- Since `i` always remains positive (and keeps growing), the condition `i > 0` never becomes False.
- Therefore, this loop runs indefinitely — it is an infinite loop.

Another simple example:
```python
while True:
print("This runs forever")
```
5Find the output of the following program segments:
(i) a = 110
while a > 100:
print(a)
a -= 2

(ii) for i in range(20,30,2):
print(i)

(iii) country = 'INDIA'
for i in country:
print(i)

(iv) i = 0; sum = 0
while i < 9:
if i % 4 == 0:
sum = sum + i
i = i + 2
print(sum)

(v) for x in range(1,4):
for y in range(2,5):
if x * y > 10:
break
print(x * y)

(vi) var = 7
while var > 0:
print('Current variable value: ', var)
var = var - 1
if var == 3:
break
else:
if var == 6:
var = var - 1
continue
print("Good bye!")
Show solution
(i)
```python
a = 110
while a > 100:
print(a)
a -= 2
```
Trace:
- Iteration 1: `a = 110`, condition `110 > 100` → True → print 110, `a = 108`
- Iteration 2: `a = 108`, condition `108 > 100` → True → print 108, `a = 106`
- Iteration 3: `a = 106`, condition `106 > 100` → True → print 106, `a = 104`
- Iteration 4: `a = 104`, condition `104 > 100` → True → print 104, `a = 102`
- Iteration 5: `a = 102`, condition `102 > 100` → True → print 102, `a = 100`
- Iteration 6: `a = 100`, condition `100 > 100` → False → loop ends

Output:
```
110
108
106
104
102
```

---

(ii)
```python
for i in range(20, 30, 2):
print(i)
```
Trace: `range(20, 30, 2)` generates: 20, 22, 24, 26, 28

Output:
```
20
22
24
26
28
```

---

(iii)
```python
country = 'INDIA'
for i in country:
print(i)
```
Trace: The `for` loop iterates over each character of the string `'INDIA'`.

Output:
```
I
N
D
I
A
```

---

(iv)
```python
i = 0; sum = 0
while i < 9:
if i % 4 == 0:
sum = sum + i
i = i + 2
print(sum)
```
Trace:

| `i` | `i < 9` | `i % 4 == 0` | `sum` | `i` after update |
|---|---|---|---|---|
| 0 | True | True (0%4=0) | 0+0=0 | 2 |
| 2 | True | False (2%4=2) | 0 | 4 |
| 4 | True | True (4%4=0) | 0+4=4 | 6 |
| 6 | True | False (6%4=2) | 4 | 8 |
| 8 | True | True (8%4=0) | 4+8=12 | 10 |
| 10 | False | — | — | loop ends |

Output:
```
12
```

---

(v)
```python
for x in range(1, 4):
for y in range(2, 5):
if x * y > 10:
break
print(x * y)
```
Trace:

- x = 1:
- y=2: 1×2=2, 2>10? No → print 2
- y=3: 1×3=3, 3>10? No → print 3
- y=4: 1×4=4, 4>10? No → print 4
- x = 2:
- y=2: 2×2=4, 4>10? No → print 4
- y=3: 2×3=6, 6>10? No → print 6
- y=4: 2×4=8, 8>10? No → print 8
- x = 3:
- y=2: 3×2=6, 6>10? No → print 6
- y=3: 3×3=9, 9>10? No → print 9
- y=4: 3×4=12, 12>10? Yes → break (inner loop ends)

Output:
```
2
3
4
4
6
8
6
9
```

---

(vi)
```python
var = 7
while var > 0:
print('Current variable value: ', var)
var = var - 1
if var == 3:
break
else:
if var == 6:
var = var - 1
continue
print("Good bye!")
```
Trace:

- Iteration 1: `var=7`, condition True → print `Current variable value: 7`, `var=6`
- `var==3`? No → else: `var==6`? Yes → `var=5`, `continue` (go back to loop start)
- Iteration 2: `var=5`, condition True → print `Current variable value: 5`, `var=4`
- `var==3`? No → else: `var==6`? No → (no action, loop continues normally)
- Iteration 3: `var=4`, condition True → print `Current variable value: 4`, `var=3`
- `var==3`? Yes → break (exit loop)
- After loop: print `Good bye!`

Output:
```
Current variable value: 7
Current variable value: 5
Current variable value: 4
Good bye!
```

PROGRAMMING EXERCISES

1Write a program that takes the name and age of the user as input and displays a message whether the user is eligible to apply for a driving license or not. (the eligible age is 18 years).Show solution
Concept: Use `if-else` to compare the entered age with the eligible age of 18.

Program:
```python
# Program to check eligibility for driving license
name = input("Enter your name: ")
age = int(input("Enter your age: "))

if age >= 18:
print("Hello", name + ", you are eligible to apply for a driving license.")
else:
print("Hello", name + ", you are NOT eligible to apply for a driving license.")
print("You need to wait for", 18 - age, "more year(s).")
```

Sample Output 1:
```
Enter your name: Riya
Enter your age: 20
Hello Riya, you are eligible to apply for a driving license.
```

Sample Output 2:
```
Enter your name: Arjun
Enter your age: 16
Hello Arjun, you are NOT eligible to apply for a driving license.
You need to wait for 2 more year(s).
```
2Write a function to print the table of a given number. The number has to be entered by the user.Show solution
Concept: Define a function that accepts a number and uses a `for` loop with `range()` to print the multiplication table.

Program:
```python
# Function to print multiplication table
def print_table(n):
print("Multiplication table of", n)
for i in range(1, 11):
print(n, "x", i, "=", n * i)

# Main program
num = int(input("Enter a number: "))
print_table(num)
```

Sample Output:
```
Enter a number: 5
Multiplication table of 5
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
```
3Write a program that prints minimum and maximum of five numbers entered by the user.Show solution
Concept: Accept five numbers from the user using a loop, then use `if` conditions to track the minimum and maximum values.

Program:
```python
# Program to find minimum and maximum of five numbers
print("Enter 5 numbers:")

# Read the first number to initialise min and max
num = int(input("Number 1: "))
min_num = num
max_num = num

for i in range(2, 6):
num = int(input("Number " + str(i) + ": "))
if num < min_num:
min_num = num
if num > max_num:
max_num = num

print("Minimum number =", min_num)
print("Maximum number =", max_num)
```

Sample Output:
```
Enter 5 numbers:
Number 1: 34
Number 2: 12
Number 3: 56
Number 4: 7
Number 5: 45
Minimum number = 7
Maximum number = 56
```
4Write a program to check if the year entered by the user is a leap year or not.Show solution
Concept: A year is a leap year if:
- It is divisible by 4 AND not divisible by 100, OR
- It is divisible by 400.

Leap year condition: (year%4==0 and year%1000) or (year%400==0)\text{Leap year condition: } (year \% 4 == 0 \text{ and } year \% 100 \neq 0) \text{ or } (year \% 400 == 0)

Program:
```python
# Program to check leap year
year = int(input("Enter a year: "))

if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print(year, "is a Leap Year.")
else:
print(year, "is NOT a Leap Year.")
```

Sample Output 1:
```
Enter a year: 2024
2024 is a Leap Year.
```

Sample Output 2:
```
Enter a year: 1900
1900 is NOT a Leap Year.
```

Sample Output 3:
```
Enter a year: 2000
2000 is a Leap Year.
```
5Write a program to generate the sequence: -5, 10, -15, 20, -25... upto n, where n is an integer input by the user.Show solution
Concept: Observe the pattern:
- The absolute values are multiples of 5: 5,10,15,20,25,5, 10, 15, 20, 25, \ldots
- The signs alternate: negative for odd terms, positive for even terms.

We use a `for` loop and a sign variable that alternates between 1-1 and +1+1.

Program:
```python
# Program to generate the sequence -5, 10, -15, 20, -25 ... upto n terms
n = int(input("Enter the number of terms (n): "))

sign = -1
for i in range(1, n + 1):
term = sign * (5 * i)
print(term, end=" ")
sign = sign * -1 # Alternate the sign

print() # For newline at the end
```

Sample Output:
```
Enter the number of terms (n): 6
-5 10 -15 20 -25 30
```
6Write a program to find the sum of 1+18+127+1n31 + \frac{1}{8} + \frac{1}{27} + \frac{1}{n^3}, where n is the number input by the user.Show solution
Given: The series is i=1n1i3=1+18+127++1n3\displaystyle\sum_{i=1}^{n} \frac{1}{i^3} = 1 + \frac{1}{8} + \frac{1}{27} + \cdots + \frac{1}{n^3}

Concept: Use a `for` loop to iterate from 1 to n, adding 1i3\dfrac{1}{i^3} to the sum in each iteration.

Program:
```python
# Program to find sum of 1 + 1/8 + 1/27 + ... + 1/n^3
n = int(input("Enter the value of n: "))

total = 0
for i in range(1, n + 1):
total = total + (1 / (i 3))

print("Sum of the series =", total)
```

Sample Output:
```
Enter the value of n: 3
Sum of the series = 1.1620370370370371
```

Verification:** 1+18+127=1+0.125+0.0370371.1621 + \dfrac{1}{8} + \dfrac{1}{27} = 1 + 0.125 + 0.037037\ldots \approx 1.162
7Write a program to find the sum of digits of an integer number, input by the user.Show solution
Concept: Repeatedly extract the last digit using the modulo operator (`% 10`) and remove it using integer division (`// 10`), adding each digit to a running sum.

Program:
```python
# Program to find sum of digits of a number
num = int(input("Enter an integer number: "))

# Work with the absolute value to handle negative numbers
original = num
num = abs(num)
digit_sum = 0

while num > 0:
digit = num % 10 # Extract last digit
digit_sum = digit_sum + digit
num = num // 10 # Remove last digit

print("Sum of digits of", original, "=", digit_sum)
```

Sample Output:
```
Enter an integer number: 4567
Sum of digits of 4567 = 22
```

Trace for 4567:
- digit = 7, sum = 7, num = 456
- digit = 6, sum = 13, num = 45
- digit = 5, sum = 18, num = 4
- digit = 4, sum = 22, num = 0 → loop ends
- Result: 22
8Write a function that checks whether an input number is a palindrome or not.
[Note: A number or a string is called palindrome if it appears same when written in reverse order also. For example, 12321 is a palindrome while 123421 is not a palindrome]
Show solution
Concept: A number is a palindrome if it reads the same forwards and backwards. We reverse the number by extracting digits one by one and compare the reversed number with the original.

Program:
```python
# Function to check if a number is a palindrome
def is_palindrome(num):
original = num
num = abs(num) # Handle negative numbers
reversed_num = 0

while num > 0:
digit = num % 10
reversed_num = reversed_num * 10 + digit
num = num // 10

if reversed_num == abs(original):
return True
else:
return False

# Main program
number = int(input("Enter a number: "))

if is_palindrome(number):
print(number, "is a Palindrome.")
else:
print(number, "is NOT a Palindrome.")
```

Sample Output 1:
```
Enter a number: 12321
12321 is a Palindrome.
```

Sample Output 2:
```
Enter a number: 123421
123421 is NOT a Palindrome.
```

Trace for 12321:
- digit=1, rev=1, num=1232
- digit=2, rev=12, num=123
- digit=3, rev=123, num=12
- digit=2, rev=1232, num=1
- digit=1, rev=12321, num=0
- reversed_num (12321) == original (12321) → Palindrome
9Write a program to print the following patterns:
i) Diamond/Rhombus pattern with *
ii) Number pattern: 1 / 2 1 2 / 3 2 1 2 3 / ...
iii) Descending number triangle
iv) Right-angled triangle with *
Show solution
**Pattern (i): Diamond shape with *)**

```python
# Pattern i: Diamond shape
n = 3 # number of rows in upper half (excluding middle)

# Upper half (including middle)
for i in range(1, 2*n, 2):
print('*' * i)

# Lower half
for i in range(2*n-2, 0, -2):
print('*' * i)
```

Output:
```
*
*
*
*
*
```
*(Note: Based on the pattern shown — *, *, *, *, * — this is a diamond.)*

---

Pattern (ii): Number palindrome pattern

```python
# Pattern ii: Number palindrome pattern
n = 5
for i in range(1, n + 1):
# Print descending part: i, i-1, ..., 1
for j in range(i, 0, -1):
print(j, end=' ')
# Print ascending part: 2, 3, ..., i
for j in range(2, i + 1):
print(j, end=' ')
print()
```

Output:
```
1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
```

---

Pattern (iii): Descending number triangle

```python
# Pattern iii: Descending number triangle
n = 5
for i in range(n, 0, -1):
for j in range(1, i + 1):
print(j, end=' ')
print()
```

Output:
```
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
```

---

**Pattern (iv): Right-angled triangle with * (hollow)**

```python
# Pattern iv: Hollow right-angled triangle with *
n = 5
for i in range(1, n + 1):
for j in range(1, i + 1):
if j == 1 or j == i or i == n:
print('*', end=' ')
else:
print(' ', end=' ')
print()
```

Output:
```
*
* *
* *
* *
* * * * *
```
10Write a program to find the grade of a student when grades are allocated as given in the table below.
Percentage of Marks | Grade
Above 90% | A
80% to 90% | B
70% to 80% | C
60% to 70% | D
Below 60% | E
Percentage of the marks obtained by the student is input to the program.
Show solution
Concept: Use `if-elif-else` ladder to compare the percentage with the given ranges and assign the appropriate grade.

Program:
```python
# Program to find grade based on percentage
percentage = float(input("Enter the percentage of marks: "))

if percentage > 90:
grade = 'A'
elif percentage >= 80: # 80 to 90
grade = 'B'
elif percentage >= 70: # 70 to 80
grade = 'C'
elif percentage >= 60: # 60 to 70
grade = 'D'
else: # Below 60
grade = 'E'

print("Percentage:", percentage)
print("Grade:", grade)
```

Sample Output 1:
```
Enter the percentage of marks: 92.5
Percentage: 92.5
Grade: A
```

Sample Output 2:
```
Enter the percentage of marks: 75.0
Percentage: 75.0
Grade: C
```

Sample Output 3:
```
Enter the percentage of marks: 55.0
Percentage: 55.0
Grade: E
```

CASE STUDY-BASED QUESTIONS

6.1Write a menu driven program that has options to:
- Accept the marks of the student in five major subjects in Class X and display the same.
- Calculate the sum of the marks of all subjects. Divide the total marks by number of subjects (i.e. 5), calculate percentage = total marks/5 and display the percentage.
- Find the grade of the student as per the following criteria:
percentage > 85 → A
percentage < 85 && percentage >= 75 → B
percentage < 75 && percentage >= 50 → C
percentage > 30 && percentage <= 50 → D
percentage < 30 → Reappear
Show solution
Concept: Use a `while` loop to keep showing the menu, `if-elif-else` for menu selection, and another `if-elif-else` ladder for grade calculation.

Program:
```python
# SMIS - Student Mark Information System
# Menu driven program for Class X marks

marks = [] # List to store marks

while True:
print("\n===== STUDENT MARK INFORMATION SYSTEM =====")
print("1. Enter marks of 5 subjects and display them")
print("2. Calculate and display percentage")
print("3. Find and display grade")
print("4. Exit")

choice = int(input("Enter your choice (1-4): "))

if choice == 1:
marks = [] # Reset marks list
subjects = ["Subject 1", "Subject 2", "Subject 3",
"Subject 4", "Subject 5"]
print("\nEnter marks out of 100 for each subject:")
for sub in subjects:
m = float(input(sub + ": "))
marks.append(m)
print("\nMarks entered:")
for i in range(5):
print(subjects[i], ":", marks[i])

elif choice == 2:
if len(marks) == 0:
print("Please enter marks first (Option 1).")
else:
total = sum(marks)
percentage = total / 5
print("\nTotal Marks =", total)
print("Percentage =", percentage, "%")

elif choice == 3:
if len(marks) == 0:
print("Please enter marks first (Option 1).")
else:
total = sum(marks)
percentage = total / 5
print("\nPercentage =", percentage, "%")

if percentage > 85:
grade = 'A'
elif percentage >= 75: # < 85 and >= 75
grade = 'B'
elif percentage >= 50: # < 75 and >= 50
grade = 'C'
elif percentage > 30: # > 30 and <= 50
grade = 'D'
else: # < 30
grade = 'Reappear'

print("Grade =", grade)

elif choice == 4:
print("Exiting the program. Goodbye!")
break

else:
print("Invalid choice! Please enter a number between 1 and 4.")
```

Sample Output:
```
===== STUDENT MARK INFORMATION SYSTEM =====
1. Enter marks of 5 subjects and display them
2. Calculate and display percentage
3. Find and display grade
4. Exit
Enter your choice (1-4): 1

Enter marks out of 100 for each subject:
Subject 1: 88
Subject 2: 76
Subject 3: 92
Subject 4: 81
Subject 5: 79

Marks entered:
Subject 1 : 88.0
Subject 2 : 76.0
Subject 3 : 92.0
Subject 4 : 81.0
Subject 5 : 79.0

Enter your choice (1-4): 2
Total Marks = 416.0
Percentage = 83.2 %

Enter your choice (1-4): 3
Percentage = 83.2 %
Grade = B

Enter your choice (1-4): 4
Exiting the program. Goodbye!
```

Stuck on a step?

Ask Super Tutor AI to explain any solution on this page in a simpler way — free, 24x7.

Ask a Doubt Free

Frequently Asked Questions

What are the important topics in Flow of Control for Assam Board Class 11 Computer Science?
Flow of Control covers several key topics that are frequently asked in Assam Board Class 11 board exams. Focus on the core concepts listed on this page and practise related questions to build confidence.
How to score full marks in Flow of Control — Assam Board Class 11 Computer Science?
Understand the core concepts first, then work through the 30 practice questions available for this chapter. Revise formulas and definitions regularly, and use flashcards for quick recall before the exam.
Where can I get free NCERT Solutions for Flow of Control Class 11 Computer Science?
This page has free step-by-step NCERT Solutions for every exercise question in Flow of Control (Assam Board Class 11 Computer Science) — written the way examiners award marks: given, formula, working, answer.

Sources & Official References

Content is aligned to the official syllabus. Refer to the board website for the latest curriculum.

For serious students

Get the full Flow of Control chapter — for free.

Quizzes, flashcards, AI doubt-solver and a step-by-step study plan for Assam Board Class 11 Computer Science.