C Programming: Loops and Control Structures

Test your knowledge of C programming loops (while, do-while, for), control structures, switch statements, and basic operators with this interactive quiz.

15 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

How many number of times will the loop mentioned below be executed?
int x=5;int y=30;while(x<=y){ x=y/x; y=y-10;}

  1. 1 time
  2. 2 time
  3. 3 time
  4. 4 time
  5. 5 time
Question 2 Multiple Choice (Single Answer)

The process of repeating sequence of instructions over and over again is called

  1. break statement
  2. continue statement
  3. iterative control structure
  4. selection structure
  5. switch statement
Question 3 Multiple Choice (Single Answer)

In 'C' language 1%2 would result in ____________

  1. '1'
  2. '2'
  3. '0'
  4. '0.5'
  5. '3'
Question 4 Multiple Choice (Single Answer)

Nested loops are used for which of the following purposes in 'C'?

  1. To execute value of control variable multiple times.
  2. To read value for one-dimensional array statement.
  3. To execute value of outer variable to specified number of times in the inner loop.
  4. To get sum and average of 'N' numbers.
  5. To compare two strings.
Question 5 Multiple Choice (Single Answer)

In which of the following statementsor loops 'continue' statement cannot be used in 'C'?

  1. while statement
  2. do-while statement
  3. for statement
  4. switch statement
  5. Nested for statement
Question 6 Multiple Choice (Single Answer)

What would be the output of the following statement?
int x=30;int y=5;while(x!=0){ if(x%y==0) printf(n Value of x=%d,x); x=x-10;}

  1. Value of x=10Value of x=20Value of x=30
  2. Value of x=30Value of x=20Value of x=10
  3. Value of x=10Value of x=30Value of x=20
  4. Value of x=30Value of x=10Value of x=20
  5. Value of x=10Value of x=20Value of x=10
Question 7 Multiple Choice (Single Answer)

What would be the value of 'j' at the end of the 'C' programming statement?int i=1234, k,j=0;do{ k=i%10; j=j*10+k; i=i/10; }while(i!=0); printf(n value of j=%d,j);

  1. 1234
  2. 423
  3. 3241
  4. 4321
  5. 123
Question 8 Multiple Choice (Single Answer)

What will be the output of the given statement?
int i=3; do { printf(%d n, i); } while(i!=0);

  1. 3 210
  2. 3 1 20
  3. 3012
  4. 321
  5. 1230
Question 9 Multiple Choice (Single Answer)

Which of the following statements in C is the correct one to find whether a triangle is an equilateral triangle or not? Let the sides of the triangle be A, B, & C.

  1. if(A==B || B==C || A==C)
  2. if(A!=C || A!=B)
  3. if(A==B==C)
  4. if(A!=B && A!=C)
  5. if(!A==B || !A==C)
Question 10 Multiple Choice (Single Answer)

Which of the following statements is the correct one for exchanging the values of two variables? If a, b & temp are three variables.

  1. a=b; b=a;
  2. temp=a;a=b;b=temp;
  3. a=b;b=temp;
  4. temp=a;a=b;
  5. None of these
Question 11 Multiple Choice (Single Answer)

Which of the following is the correct choice for making use of 'do-while' loop in a program?

  1. When we do not know the initial value for loop index variable.
  2. When we know value for loop index variable.
  3. When there is no test condition in the loop.
  4. When there is test condition in the beginning of the loop.
  5. When there is no increment statement in the loop.
Question 12 Multiple Choice (Single Answer)

What would be the conclusion of the following statement in 'C'?
int i=5;for(;;){ printf(n Value of i=%d,i);}

  1. Infinite loop will be generated.
  2. value of i=10
  3. i=6
  4. Printf() statement would not be executed.
  5. Syntax error in the program.
Question 13 Multiple Choice (Single Answer)

What would be the output of the following 'C' statement?

void main()
{
int i=1, j=5;
while(i<j)
{
printf("value of i= %d", i);
i++;
}
}

  1. value of i=1value of i=2value of i=3value of i=4
  2. Value of i=1value of i=2value of i=3value of i=4value of i=5
  3. Value of i=1value of i=4
  4. Value of i=1value of i=5
  5. Value of i=1value of i=3value of i=4
Question 14 Multiple Choice (Single Answer)

What would be the output of the following statement in 'C'? int i=0; for(i=0;i<5;) { switch(i) { case 0: printf(n Number is Zero!); break; case 1: printf(n Number is One!); break; case 2: printf(n Number is Two!); break; } i=i+2; }

  1. Number is ZeroNumber is One
  2. Number is OneNumber is Two
  3. Number is ZeroNumber is Two
  4. Number is OneNumber is Zero
  5. Number is TwoNumber is One
Question 15 Multiple Choice (Single Answer)

What would be the output of the following statement in 'C'? int i=0; do { i=i+3; printf(n i=%d,i); }while(i<5);

  1. i=3
  2. i=3i=6
  3. i=960
  4. i=3i=5
  5. i=6i=3