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.
Questions
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 time
- 2 time
- 3 time
- 4 time
- 5 time
The process of repeating sequence of instructions over and over again is called
- break statement
- continue statement
- iterative control structure
- selection structure
- switch statement
In 'C' language 1%2 would result in ____________
- '1'
- '2'
- '0'
- '0.5'
- '3'
Nested loops are used for which of the following purposes in 'C'?
- To execute value of control variable multiple times.
- To read value for one-dimensional array statement.
- To execute value of outer variable to specified number of times in the inner loop.
- To get sum and average of 'N' numbers.
- To compare two strings.
In which of the following statementsor loops 'continue' statement cannot be used in 'C'?
- while statement
- do-while statement
- for statement
- switch statement
- Nested for statement
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;}
- Value of x=10Value of x=20Value of x=30
- Value of x=30Value of x=20Value of x=10
- Value of x=10Value of x=30Value of x=20
- Value of x=30Value of x=10Value of x=20
- Value of x=10Value of x=20Value of x=10
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);
- 1234
- 423
- 3241
- 4321
- 123
What will be the output of the given statement?
int i=3; do { printf(%d n, i); } while(i!=0);
- 3 210
- 3 1 20
- 3012
- 321
- 1230
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.
- if(A==B || B==C || A==C)
- if(A!=C || A!=B)
- if(A==B==C)
- if(A!=B && A!=C)
- if(!A==B || !A==C)
Which of the following statements is the correct one for exchanging the values of two variables? If a, b & temp are three variables.
- a=b; b=a;
- temp=a;a=b;b=temp;
- a=b;b=temp;
- temp=a;a=b;
- None of these
Which of the following is the correct choice for making use of 'do-while' loop in a program?
- When we do not know the initial value for loop index variable.
- When we know value for loop index variable.
- When there is no test condition in the loop.
- When there is test condition in the beginning of the loop.
- When there is no increment statement in the loop.
What would be the conclusion of the following statement in 'C'?
int i=5;for(;;){ printf(n Value of i=%d,i);}
- Infinite loop will be generated.
- value of i=10
- i=6
- Printf() statement would not be executed.
- Syntax error in the program.
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++;
}
}
- value of i=1value of i=2value of i=3value of i=4
- Value of i=1value of i=2value of i=3value of i=4value of i=5
- Value of i=1value of i=4
- Value of i=1value of i=5
- Value of i=1value of i=3value of i=4
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; }
- Number is ZeroNumber is One
- Number is OneNumber is Two
- Number is ZeroNumber is Two
- Number is OneNumber is Zero
- Number is TwoNumber is One
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);
- i=3
- i=3i=6
- i=960
- i=3i=5
- i=6i=3