COMPUTER SCIENCE 
IMPORTANT QUESTIONS ON CHAPTER 4 AND 5 (INTRODUCTION TO LOOPS AND NESTED LOOP IN C
FOR EXAM.

Important questions Chapters 4 and 5

1.       Fill in the blanks:

a.       Do while loop will execute at least once.

b.       Modules (%) operator is used to find remainder when a number is divided by another number.

c.       The break statement is used to exit from the loop when meet a condition.

d.       A C statement terminate with a semicolon.

2.       State true or false:

a.       The statement inside the while loop executes at least once even the condition is false. True

b.       If the condition of the while loop is false, the control comes to the second statement inside the loop. False

c.       There cannot be ore than one inner loop in a program. False

d.       In do while loop condition is written at the end of the loop. True

e.       If the condition of the while loop is false, the control comes o the outside of the loop. True

f.        There cannot be more than one inner loop in a program. False

3.       MCQ

a.       Which loop is guarantee to execute at least one time?

(for / while/ do while/ none of these)

b.       The condition in do while loop is evaluated

i)                    After execution of statements

ii)                   Before execution of statements

iii)                 Both i) and ii)

iv)                 None of these

4.       Answer in one word:

a.       It is used for repeated execution of a set of statements in a program. Loop

b.       It is an exit control loop. Do while loop

c.       What is the use of include statement.

Ans: Include statement is used top tell the compiler to include the specified header file along with the program while compiling.

d.       Write another pattern of i+=2 operator. i = i + 2;

e.       Name one loop construct that can be used in inner as well as outer loop. For loop

f.        Name the statement used to skip the rest of the loop when a condition or criteria is met. Break

g.       it is a third expression of a for loop that update the variable each time the loop is executed.

Update expression.

h.       The loop that never ends is called. Infinite loop

5.       Answer the following : 2

a.       Write the syntax of for loop.

Ans: The syntax for loop is:

  for(initialization; condition; increment/decrement)

              {

                             Statements;

              }

b.       What is nested loop? why do we use?

Loop inside a loop is called nested loop. we use nested loop for. Nested loops are used in programming to perform repetitive tasks that involve multiple levels of iteration. They are essential for solving a wide range of problems and working with multi-dimensional data structures.

 

c.       Different between while and do while loop.

Different between while and do while loop are:

While

Do while

a.       It is an entry control loop

a.       It is an exit control loop

b.       The condition of the loop is checked at the beginning of the loop.

b.       The condition of the loop is checked at the end of the loop.

c.       If the condition of the loop is false, it come out from the loop.

c.       It can execute at least once, even the condition is false.

 

d.       How many time the following loop will execute?

i)                    i = 0;

while(i<=7)

{

   printf(“%d”, i);

   i = 1+3;

}

              Ans : 3 times

ii)                   i = 0;

while( i >=7)

{

  printf(“%d”. i)

}

              Ans: 0 times

e.       Why we use loop in C program?

We use loops in C programs to repeat a set of instructions multiple times, making the computer do a task over and over again without writing the same code repeatedly. This saves time and makes our programs more efficient.

f.        Write a syntax of nested while loop.

while (condition)

{

                             while(condition)

              {

                             Statements;

              }

}

g.       What types of loops can be nested?

All types of loop can be nested. The most common loop of nesting is for loop.

6.       Answer the following questions: 3

a.       Do you need to use only one type of loop in a C program? Justify your answer by writing a C program.

No, We do not need to use only one type of loop in a C program. The choice of which loop to use depends on the specific requirements of our program and the problem we are trying to solve.

Here's a simple example of C program that uses both for and while loops.

#include <stdio.h>

int main() {

    // Using a for loop to print numbers from 1 to 5

    printf("Using a for loop:\n");

    for (int i = 1; i <= 5; i++) {

        printf("%d ", i);

    }

    printf("\n");

 

    // Using a while loop to print numbers from 6 to 10

    printf("Using a while loop:\n");

    int j = 6;

    while (j <= 10) {

        printf("%d ", j);

        j++;

    }

    printf("\n");

 

    return 0;

}

b.       Write  a C program to print “I read in class X” 5 times.

{

int i=1;

for(i=1; i<=5; i++)

{     

       printf(“”I read in class X\n”);

}

return 0;

}

c.       Draw a flow chart to calculate and display the summation of 10 number.

d.       Draw a flow chart to find the summation of integers.

e.       Write a program to input a number and check if it is a prime or not.

a.       Write a C program to find the summation of digits of an integer number.

#Include<stdio.h>

int main()

{

int n, digit, sum=0;

printf(“Enter a number\n”);

scanf(“%d’, &n);

while(n<0)

{

       digit=n%10;

       sum = sum+digit;

       n=n/10;

}

printf(“The summation is %d”, sum);

return 0;

}

b.       What is nested loop? what do you mean by inner and outer loop? Give the syntax of inner and outer loop.

A nested loop is a loop that is placed inside another loop. In programming, loops are used to execute a block of code repeatedly, and when one loop is placed inside another, it creates a hierarchical structure, with one loop being the "outer loop" and the other being the "inner loop."

Syntax:

Outer Loop:

  for (outerInitialization; outerCondition; outerIncrement)  // Outer loop statements

{

   

    for (innerInitialization; innerCondition; innerIncrement) {// Inner loop statements

       {

        statements;

       }

       statements;

  }

1.      

INTRODUCTION TO LOOP


Table of Content