Fbise Notes-Computer | Loop Control Structure | Short Questions ch.no 5 class 10th

loop control sturcture

Loop Control Structure CH# 05

          

  HAPPY NEW YEAR 2021


Short Questions and Answers



i.   Differentiate between For Loop and While Loop.


Ans:   For Loop:
A loop used to execute a set of statements repeatedly for a fixed number of times in a          program is called a for loop.

       While Loop:
A loop used to implement repetition structure in a program when the number of iteration is not known in advance and the repetition continues until some condition remains true is called a while loop.

  ➤➤➤➤➤➤➤➤➤➤➤➤ 

ii. Differentiate between While and do While Loop.


Ans:   While Loop:
A loop used to implement repetition structure in a program when the number of iteration is not known in advance and the repetition continues until some condition remains true is called a while loop.

  1. It is pre-tested loop.
  2. The iteration do not occur if the condition at the first iteration appears false.
  3. Controlling condition appears at the start.
      Syntax:

     while (condition)
       {
       statements; // body of the loop.

            }       


    Do While Loop:
               In do while loop the controlling condition appears at the end of the loop.

  1. It is post-tested loop
  2. The iteration occurs at least once even if the condition is false at the first iteration.
     Syntax:

      do {
       statements; // body of the loop.

            } (while condition);      


  ➤➤➤➤➤➤➤➤➤➤➤➤ 

iii.    What will be the output of the following code?

                                              int k;
                                              for (k=1;k<=5;k++)
                                                         printf(\"I am a student");
                                               printf("\n GOOD BYE");


Ans:  I am a student
          I am a student
          I am a student
          I am a student
          I am a student
          GOOD BYE
  ➤➤➤➤➤➤➤➤➤➤➤➤ 


iv. What will be the output of the following code?

                                           int n;
                                              for (n=30;n>=10;n=n-5)
                                                         printf(\"%d",n);
                                           


Ans:         30
                 25
                 20
                 15
                 10

         
  ➤➤➤➤➤➤➤➤➤➤➤➤ 



v.  Find errors in the following code.

                                  int k,a
                                  a=3;
                                  k=1;
                                  while (k<10);
                                {
                                              printf(\n%f\t%f",k,k*a-1);
                                              k=k+2;

                                   }


Ans:                         int a,k;
                                  a=3;
                                  k=1;
                                  while (k<10)
                                {
                                              printf(\n%d\t%d",k,k*a-1);
                                              k=k+2;

                                   }

Output:

        1           2
        3           8
        5          14
        7          20
        9          26



  ➤➤➤➤➤➤➤➤➤➤➤➤ 


vi. Convert the following for loop into a while loop?


                                              int k;
                                              for (k=25;k>0;k=k-3)
                                                         printf(\"%d",k);

Ans:

                   int k;
                  k=25;
                 while (k>0)
                 {
                               printf(\"%d",k);
                               k=k-3;
                  }
                         
  ➤➤➤➤➤➤➤➤➤➤➤➤ 

                                          
                                          
Fbise Notes-Computer | Loop Control Structure | Short Questions ch.no 5 class 10th Fbise Notes-Computer | Loop Control Structure | Short Questions ch.no 5 class 10th Reviewed by fbisenotes on August 23, 2019 Rating: 5

1 comment:

Powered by Blogger.