Current Affairs updated daily
KalviGavaniKalviGavani
Class 11 · CBSE

Flow of Control — NCERT Class 11 Computer Science

Complete NCERT Solutions for CBSE Class 11 Computer Science Chapter 6 — all exercise questions on if-elif-else, for loop, while loop, break, continue, nested loops answered with working Python code.

Updated 11 June 20268 min read

NCERT Solutions: Flow of Control — CBSE Class 11 Computer Science

This page provides complete NCERT exercise solutions for CBSE Class 11 Computer Science Chapter 6 — Flow of Control. Every question is answered with a clear explanation and working Python code.


How to Use These Solutions

1. Attempt each question yourself first — write the code on paper or in IDLE before looking at the answer. 2. Compare your approach — check the logic, indentation, variable names, and output format. 3. Understand every line — if anything is unclear, revisit the [chapter guide](/class/11/computer-science/cbse-flow-of-control) for the concept. 4. Run the code — type each program in IDLE and verify the output matches what is shown. 5. Fix your mistakes — record errors in a mistake notebook and re-attempt the question the next day.


Key Concepts Quick Review

ConceptKey Point
ifExecutes block when condition is True
if-elseTwo paths — one for True, one for False
if-elif-elseMultiple conditions checked top to bottom
for loopUse when number of iterations is known
range(start, stop, step)Generates integers; stop value is excluded
while loopUse when number of iterations is unknown
breakExits the innermost loop immediately
continueSkips rest of current iteration, goes to next
passDoes nothing; placeholder statement
else with loopRuns when loop completes without break
Nested loopsInner loop runs fully for each outer iteration

Exercise Solutions

Q1. Write a program to check whether a number is even or odd.

# Program to check even or odd
num = int(input("Enter a number: "))
if num % 2 == 0:
    print(f"{num} is even")
else:
    print(f"{num} is odd")

Output:

Enter a number: 17 17 is odd
Enter a number: 24 24 is even

Q2. Write a program to find the largest of three numbers.

# Program to find the largest of three numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))

if a >= b and a >= c:
    largest = a
elif b >= a and b >= c:
    largest = b
else:
    largest = c

print(f"The largest number is {largest}")

Output:

Enter first number: 12 Enter second number: 45 Enter third number: 23 The largest number is 45

Q3. Write a program to print the multiplication table of a number entered by the user.

# Program to print multiplication table
num = int(input("Enter a number: "))
print(f"Multiplication table of {num}:")
for i in range(1, 11):
    print(f"{num} x {i} = {num * i}")

Output:

Enter a number: 7 Multiplication table of 7: 7 x 1 = 7 7 x 2 = 14 7 x 3 = 21 7 x 4 = 28 7 x 5 = 35 7 x 6 = 42 7 x 7 = 49 7 x 8 = 56 7 x 9 = 63 7 x 10 = 70

Q4. Write a program to find the factorial of a number using a loop.

# Program to find factorial using for loop
n = int(input("Enter a number: "))

if n < 0:
    print("Factorial is not defined for negative numbers")
else:
    fact = 1
    for i in range(1, n + 1):
        fact *= i
    print(f"Factorial of {n} = {fact}")

Output:

Enter a number: 5 Factorial of 5 = 120

Q5. Write a program to print the Fibonacci series up to n terms.

The Fibonacci series starts with 0 and 1. Each next term is the sum of the two previous terms.

# Program to print Fibonacci series
n = int(input("Enter number of terms: "))

if n <= 0:
    print("Please enter a positive number")
elif n == 1:
    print(0)
else:
    a, b = 0, 1
    print(a, b, end=" ")
    for i in range(2, n):
        c = a + b
        print(c, end=" ")
        a = b
        b = c
    print()

Output:

Enter number of terms: 8 0 1 1 2 3 5 8 13

Q6. Write a program to print the following star pattern:

* * * * * * * * * * * * * * *
# Program to print right-angled triangle star pattern
n = int(input("Enter number of rows: "))
for i in range(1, n + 1):
    for j in range(i):
        print("*", end=" ")
    print()

Output:

Enter number of rows: 5 * * * * * * * * * * * * * * *

Q7. Write a program to check whether a number is prime or not.

A prime number is divisible only by 1 and itself. We check divisibility from 2 to n-1.

# Program to check if a number is prime
n = int(input("Enter a number: "))

if n <= 1:
    print(f"{n} is not a prime number")
else:
    for i in range(2, n):
        if n % i == 0:
            print(f"{n} is not a prime number (divisible by {i})")
            break
    else:
        print(f"{n} is a prime number")

Output:

Enter a number: 17 17 is a prime number
Enter a number: 15 15 is not a prime number (divisible by 3)

Note: This solution uses the for-else construct. The else block runs only when the loop completes without hitting break, meaning no divisor was found.


Q8. Write a program to find the sum of digits of a number using a while loop.

# Program to find sum of digits
num = int(input("Enter a number: "))
temp = abs(num)  # handle negative numbers
digit_sum = 0

while temp > 0:
    digit_sum += temp % 10
    temp //= 10

print(f"Sum of digits of {num} = {digit_sum}")

Output:

Enter a number: 12345 Sum of digits of 12345 = 15

Q9. Write a program to find the reverse of a number using a while loop.

# Program to reverse a number
num = int(input("Enter a number: "))
temp = abs(num)
rev = 0

while temp > 0:
    rev = rev * 10 + temp % 10
    temp //= 10

if num < 0:
    rev = -rev

print(f"Reverse of {num} = {rev}")

Output:

Enter a number: 1234 Reverse of 1234 = 4321

Q10. Write a program to check whether a number is a palindrome.

A palindrome number reads the same forwards and backwards (e.g., 121, 1331).

# Program to check palindrome number
num = int(input("Enter a number: "))
temp = num
rev = 0

while temp > 0:
    rev = rev * 10 + temp % 10
    temp //= 10

if num == rev:
    print(f"{num} is a palindrome")
else:
    print(f"{num} is not a palindrome")

Output:

Enter a number: 121 121 is a palindrome
Enter a number: 123 123 is not a palindrome

Q11. Write a program to print all prime numbers between two given numbers using nested loops and break.

# Program to print prime numbers in a range
start = int(input("Enter start of range: "))
end = int(input("Enter end of range: "))

print(f"Prime numbers between {start} and {end}:")
for num in range(start, end + 1):
    if num <= 1:
        continue
    for i in range(2, num):
        if num % i == 0:
            break
    else:
        print(num, end=" ")
print()

Output:

Enter start of range: 10 Enter end of range: 30 Prime numbers between 10 and 30: 11 13 17 19 23 29

Q12. Write a program to demonstrate the use of break and continue in a loop.

# Program to demonstrate break and continue

# break: find first number divisible by both 3 and 5
print("Using break:")
for i in range(1, 100):
    if i % 3 == 0 and i % 5 == 0:
        print(f"First number divisible by both 3 and 5 is {i}")
        break

# continue: print numbers 1 to 10, skipping multiples of 3
print("\nUsing continue — numbers 1 to 10 (skip multiples of 3):")
for i in range(1, 11):
    if i % 3 == 0:
        continue
    print(i, end=" ")
print()

Output:

Using break: First number divisible by both 3 and 5 is 15 Using continue — numbers 1 to 10 (skip multiples of 3): 1 2 4 5 7 8 10

Related Pages

  • [Flow of Control — Chapter Guide](/class/11/computer-science/cbse-flow-of-control)
  • [Getting Started with Python — Chapter Guide](/class/11/computer-science/cbse-getting-started-python)
  • [Getting Started with Python — Exercise Solutions](/class/11/computer-science/solutions/cbse-getting-started-python-exercise-solutions)

Frequently Asked Questions

This page has complete NCERT exercise solutions for CBSE Class 11 Computer Science Chapter 6 Flow of Control with working Python code.
← Browse all Class 11 Exercise Solutions

Other question types — same chapter