0

Programming in 'C'

Description: 'C'
Number of Questions: 15
Created by:
Tags: -C- Looping Iteration Operators and Expression
Attempted 0/15 Correct 0 Score 0

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


Correct Option: D
Explanation:

This is the correct option as value of x becomes equal to value of y after 4 iteration. When both x and y values become equal to '0'.

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


Correct Option: C
Explanation:

This structure allows a user to repeat a group of instructions until specified condition becomes false.

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

  1. '1'

  2. '2'

  3. '0'

  4. '0.5'

  5. '3'


Correct Option: A
Explanation:

This is the correct option as modulus function would result the remainder.

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.


Correct Option: C
Explanation:

This is the correct option as in the nested loop statement inner loop is repeated specified number of times for each value of control variable in the outer loop.

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


Correct Option: D
Explanation:

This is the correct option as 'continue' statement is used to skip the current iteration and continue with the next iteration in a program 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;}

  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


Correct Option: B
Explanation:

This is the correct option as value of x is decremented by 10 in each iteration and when value of x becomes equal to 10 when it is further decremented by 10 then the condition specified in the while statement becomes true and there would not be execution of printf() statement.

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


Correct Option: D
Explanation:

This is the correct output or value of 'j' as the statement inside the loop will get the remainder of 'i' and decrement the value of 'i' by one digit after each iteration and 'j' will record the reverse of 'i'.

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


Correct Option: D
Explanation:

This is the correct output for the above statement as the value of i is displayed until it becomes less than 1.

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)


Correct Option: C
Explanation:

When all the three sides of a triangle are equal then it is called equilateral triangle. This is true in this statement.

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


Correct Option: B
Explanation:

This is the correct assignment.

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.


Correct Option: A
Explanation:

This is the correct reason to make use of do-while loop in a program as the condition is verified at the end in do-while loop.

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.


Correct Option: A
Explanation:

This is the correct option as in the statement initialization, condition and increment statements are not present and in the absence of these statements infinite loop is generated.

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


Correct Option: A
Explanation:

This is the correct output of the 'C' statement as in the while statement until the condition becomes false the value of 'i' will be printed on the screen.

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


Correct Option: C
Explanation:

This is the correct option as 'i' is incremented to 2 after each iteration.

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


Correct Option: B
Explanation:

This is the correct option as in do while statement control variable value is incremented before checking the condition.

- Hide questions