Class 10 Computer Science Chapter 5 SEBA : Nested loops in C – Important Question Answers

Class 10 Computer Science Chapter 5 SEBA : Nested loops in C – Important Question Answers

Class 10 Computer Science Chapter 5 seba : Nested loops in C, Class 10 Computer Science Chapter 5 seba question answers, chapter 5 computer science class 10 seba, computer science class 10 chapter 5 seba, Nested Loops in C class 10 seba computer science

SEBA Class 10 Computer Science Chapter 5 – Nested Loops in C: In this chapter, students learn about nested loops in C programming and how one loop can be placed inside another loop to solve different programming problems. This page provides exercise answers, solutions and explanations for Chapter 5 according to the SEBA Class 10 Computer Science syllabus.

These Class 10 Computer Science Nested Loops in C exercise answers are explained in a simple and student-friendly way to help learners understand the concepts, write C programs correctly and prepare for examinations.

Class 10 Computer Science Chapter 5 seba : Nested loops in C, Class 10 Computer Science Chapter 5 seba question answers, chapter 5 computer science class 10 seba, computer science class 10 chapter 5 seba, Nested Loops in C class 10 seba computer science

Class 10 Computer Science Chapter 5 seba : Nested loops in C, Class 10 Computer Science Chapter 5 seba question answers, chapter 5 computer science class 10 seba, computer science class 10 chapter 5 seba, Nested Loops in C class 10 seba computer science

SEBA Class 10 Computer Science Chapter 5: Nested Loops in C : Exercise Questions and Answers :

1. Write C programs to display the following patterns using nested loop construct.

a. Print the following pattern:
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
Answer:
#include<stdio.h>
int main( )
{
            int k, a;
            for (k=1; k<=5; k++)
            {
                        for(a=1; a<=3; a++)
                        printf(“%d”, a);
                        printf(“\n”);
            }
return 0;
}
b. Print the following pattern:
1 2 1
1 2 1
1 2 1
1 2 1
1 2 1
Answer:
#include<stdio.h>
int main( )
{
            int k, a, b;
            for (k=1; k<=5; k++)
            {
            for(a=1; a<=2; a++)
                        printf(“%d”, a);
            for(b=1; b<=1; b++)
                        printf(“%d”, b);
                        printf(“\n”);
            }
return 0;
}
c. Print the following pattern:
4 3 2 1
4 3 2 1
4 3 2 1
4 3 2 1
4 3 2 1
Answer:
#include<stdio.h>
int main( )
{
            int k, a;
            for (k=1; k<=5; k++)
            {
                        for(a=4; a>=1; a- -)
                        printf(“%d”, a);
                        printf(“\n”);
            }
return 0;
}
d. Print the following pattern:
        2
    2  3  4
2  3  4  5  6
Answer:
#include<stdio.h>
int main( )
{
            int k, a, b;
            for (k=1; k<=3; k++)
            {
                        for(a=1; a<=(3-k); a++)
                        printf(” “);
                        for(b=2; b<=(2*k); b++)
                        printf(“%d”, b);
                        printf(“\n”);
            }
return 0;
}
e. Print the following pattern:
        1
    1  2  1
1  2  3  2  1
Answer:
#include<stdio.h>
int main( )
{
            int k, a, b, c;
            for (k=1; k<=3; k++)
            {
                        for(a=1; a<=(3-k); a++)
                                    printf(” “);
                        for(b=1; b<=k; b++)
                                    printf(“%d”, b);
                        for(c= (k-1) ; c>=1 ; c- -)
                                    printf(“%d”, c);
                        printf(“\n”);
            }
return 0;
}
f. Print the following pattern:
               *
         *    *    *
    *   *   *    *   *
*   *   *   *    *   *   *
    *   *   *    *   *
          *   *    *
              *
Answer:
#include<stdio.h>
int main( )
{
int k, a, b, c;
          for(k=1 ; k<=4 ; k++)
          {
             for(a=1 ; a<=(4-k) ; a++)
                printf(” “);
             for(b=1 ; b<=(k*2-1); b++)
                printf(“*“);
              printf(“\n”);
          }
          for(k=1 ; k<=3 ; k++)
          {
            for(a=1 ; a<=k ; a++)
                printf(” “);
            for(b=5 ; b>=(2*k-1); b- -)
                printf(“*“);
             printf(“\n”);
          }
return 0;
}
g. Print the following pattern:
        X                      X
        X  X                  X  X
        X  X  X             X  X  X
        X  X  X  X  X     X  X  X  X
        X  X  X  X  X  X  X  X  X  X  X
 
Answer:
#include<stdio.h>
int main( )
{
     int k, a, b ;
     for(k=1 ; k<=5 ; k++)
     {
          for(a=1 ; a<=k ; a++)
              printf(“x“);
          for(b=1 ; b<=(5-k); b++)
              printf(” “);
          for(a=1 ; a<=k ; a++)
              printf(“x“);
       printf(“\n”);
     }
return 0;
}
Class 10 Computer Science Chapter 5 seba : Nested loops in C, Class 10 Computer Science Chapter 5 seba question answers, chapter 5 computer science class 10 seba, computer science class 10 chapter 5 seba, Nested Loops in C class 10 seba computer science

(Class 10 Computer Science Chapter 5 seba : Nested loops in C, Class 10 Computer Science Chapter 5 seba question answers, chapter 5 computer science class 10 seba, computer science class 10 chapter 5 seba, Nested Loops in C class 10 seba computer science)

2. Modify the solution of question no. 1 to accept the number of lines as the input. The program should make the display pattern accordingly (Hint write separate programs).
Answer:
Please find the modified program below of Q. 1 (a) :-
#include<stdio.h>
int main( )
{
          int k, a, N;
          printf(“Enter the value of N:”);
          scanf(“%d” , &N);
         for (k=1; k<=N; k++)
          {
            for(a=1; a<=3; a++)
               printf(“%d”, a);
             printf(“\n”);
            }
 return 0;
}
4. What is nested loop? Why do we use nested loops in our programs?
Answer:
Whenever we write a loop inside another loop, it is called a nested loop. A nested loop is divided into two parts: outer loop and inner loop.
We use nested loops for the following reasons:-
i) To reduce the length of the program.
ii) To save time and effort.
iii) To make the program easier and simpler than using separate loops.
5. Do we need to use same type of loops as outer and inner loops? Justify your answer with some code segments.
Answer:
No, we don not need to use same type of loops as outer and inner loops.
Some code segments are given below to justify:
#include<stdio.h>
int main( )
{
    int k, i ;
    for (k=1; k<=2; k++)
     {
          i=1 ;
          while(i<=2)
           {
             printf(“I read in class 10 \n”) ;
            i++ ;
            }
        printf(“\n”) ;
      }
return 0 ;
}
Output of the code:
I read in class 10
I read in class 10
I read in class 10
I read in class 10

On the above code, we used a for loop as the outer loop, and a while loop as the inner loop.
6. Can we put a third inside the inner loop of a nested loop construct? Write a C program to justify your answer.
Answer:
Yes, we can put third loop inside the inner loop of a nested loop construct.
A program given below to justify:
#include<stdio.h>
int main( )
{
          int a, b, c ;
          for(a=1 ; a<=3; a++)
          {
              for(b=1 ; b<=3 ; b++)
              {
                for(c=1 ; c<=1 ; c++)
                printf(” X “) ;
              }
              printf(“\n”) ;
          }
return 0 ;
}

Output of the program:
X X X
X X X
X X X

Related Class 10 Computer Science Chapters of SEBA :

→ Chapter 1 SEBA : Introduction to Computer Network
→ Chapter 4 SEBA : Introduction to Loops
→ Chapter 6 SEBA : Arrays in C
→ Chapter 7 SEBA : Functions in C

(Class 10 Computer Science Chapter 5 seba : Nested loops in C, Class 10 Computer Science Chapter 5 seba question answers, chapter 5 computer science class 10 seba, computer science class 10 chapter 5 seba, Nested Loops in C class 10 seba computer science)

Class 10 Computer Science Chapter 5 seba : Nested loops in C, Class 10 Computer Science Chapter 5 seba question answers, chapter 5 computer science class 10 seba, computer science class 10 chapter 5 seba, Nested Loops in C class 10 seba computer science

Definition

A nested loop in C is a loop placed inside another loop. The inner loop executes completely for each single iteration of the outer loop. C supports nesting of any loop type (for, while, or do-while) inside any other, and they can be nested to multiple levels.

This comprehensive guide features solved SEBA Class 10 Computer Science Chapter 5: Nested Loops in C questions and answers, designed specifically for Assam Board exam preparation. Learn the core principles of nested loop execution, outer versus inner loop control structures, break/continue statement behaviors, and step-by-step pattern printing programs in simple, easy-to-understand C code. Perfect for Class 10 students, teachers, and computer science beginners looking for clear notes, important board exam questions, pattern output solutions, and quick revision materials to boost exam performance.

Syntax of Nested loop

for (initialization1; condition1; update1)
{ // Outer loop body
for (initialization2; condition2; update2)
{
// inner loop body
}
}
Class 10 Computer Science Chapter 5 seba, Class 10 Computer Science Chapter 5 seba question answers, chapter 5 computer science class 10 seba, computer science class 10 chapter 5 seba, Nested Loops in C class 10 seba computer science
Class 10 Computer Science Chapter 5 seba, Class 10 Computer Science Chapter 5 seba question answers, chapter 5 computer science class 10 seba, computer science class 10 chapter 5 seba, Nested Loops in C class 10 seba computer science

How Nested loop Works

  • The outer loop runs first and enters its body.
  • The inner loop then executes from start to finish.
  • Control returns to the outer loop, which performs its next iteration, and the inner loop runs again from the beginning.
  • This continues until the outer loop’s condition becomes false.

If the outer loop runs m times and the inner loop runs n times per outer iteration, the inner loop body executes a total of m × n times.

error: Content is protected !!