Wednesday 3 June 2020

UGC NET Computer Science December 2019 | Question 64

Question 64
What is the output of following C program?
# include <stdio.h>
main( )
{
int i, j, x = 0 ;
for ( i= 0; i < 5; ++i )
for ( j = 0; j < i ; ++j ){
x += (i + j - 1);
break ;
}
printf ( "%d" , x );
  1. 1. 6
  2. 2. 5
  3. 3. 4
  4. 4. 3
Explanation
Inner for loop will not execute while i = 0, as j < i condition is not met.

Break statement restricts inner-for-loop to execute only once for all value of i > 0

Inner for loop value j initializes to 0 every time.

ij(i+j-1)value of x
00inner loop not execute as j is not less than i0
10(1 + 0 - 1) = 00
20(2 + 0 - 1) = 11
30(3 + 0 - 1) = 23
40(4 + 0 - 1) = 36

So, option 1 is correct answer

PreviousNext
UGC NET CS December 2019 - Question 63UGC NET CS December 2019 - Question 65

No comments:

Post a Comment

UGC NET Computer Science December 2019 | Question 16

Question 16 In a certain coding language. 'AEIOU' is written as 'TNHDZ'. Using the same coding language. 'BFJPV' wil...

Popular Posts