Programming

 Question 1
Consider the following code segment
for (int k=0; k<20; k=k+2)
{
if (k % 3 == 1)
system.out.print(k+ " ")
}
What is printed as a result of executing the code segment?
 A 4 16 B 4 10 16 C 0 6 12 18 D 1 4 7 10 13 16 19
Programming-for-Output-Problems       Programming       ISRO CS 2008
Question 1 Explanation:
for loop starts from 0 to 20 and increments with 2 at each iteration.
k = 0 % 3 = 0
k = 2 % 3 = 2
k = 4 % 3 = 1 // prints 4
k = 6 % 3 = 0
k = 8 % 3 = 2
k = 10 % 3 = 1 // prints 10
k = 12 % 3 = 0
k = 14 % 3 = 2
k = 16 % 3 = 1 // prints 16
k = 18 % 3 = 0
So, Output is 4 10 16
 Question 2
What is the value of F(4) using the following procedure:
function F(K : integer)
integer;
begin
if (k<3) then F:=k
else F:=F(k-1)*F(k-2)+F(k-3)
end;
 A 5 B 6 C 7 D 8
Data-Structures       Programming       ISRO CS 2008
Question 2 Explanation:

F(4) = F(3)*F(2)+F(1) = 5

F(3) = F(2)*F(1)+F(0) = 2

F(2) = 2

F(1) = 1

F(0) = 0
 Question 3
In C, what is the effect of a negative number in a field width specifier?
 A the values are displayed right justified B the values are displayed centered C the values are displayed left justified D the values are displayed as negative numbers
C-Language       Programming       ISRO CS 2008
Question 3 Explanation:
To left justify, use a negative number in the field width:
Controlling integer width with printf
The %3d specifier is used with integers, and means a minimum width of three spaces, which, by default, will be right-justified: Left-justifying printf integer output
To left-justify integer output with printf, just add a minus sign ( - ) after the % symbol, like this: The printf integer zero-fill option
To zero-fill your printf integer output, just add a zero (0) after the % symbol, like this: Question 4
Consider the following code written in a pass-by-reference language like FORTRAN and these statements about the code.
subroutine swap(ix,iy)
it = ix
L1 : ix = iy
L2 : iy = it
end
ia = 3
ib = 8
call swap (ia, ib+5)
print *, ia, ib
end
S1: The compiler will generate code to allocate a temporary nameless cell, initialize it to 13, and pass the address of the cell to swap
S2: On execution the code will generate a runtime error on line L1
S3: On execution the code will generate a runtime error on line L2
S4: The program will print 13 and 8
S5: The program will print 13 and -2
Exactly the following set of statement(s) is correct:
 A S1 and S2 B S1 and S4 C S3 D S1 and S5
Programming-in-c++       Programming       ISRO CS 2009
Question 4 Explanation:
Swap operation perform between the ia and temporary nameless cell, therefore the value of ib is remains unchanged.
Swap (8, 13)
⇒ ia will returns value with 13.
⇒ ib is unchanged, because here we using pass by reference value.
➝ Temporary nameless is initialized to 13.
➝ There is No runtime error.
 Question 5
Find the output of the following Java code line System.out.println(math.floor(-7.4))
 A -7 B -8 C -7.4 D -7
Java       Programming       ISRO CS 2011
Question 5 Explanation:
The method floor gives the largest integer that is less than or equal to the argument.
But here the argument is negative value.
Floor of -7.4 will return the lower limit, i.e. -8.
 Question 6
Consider the following pseudocode:
x:=1;
i:=1;
while (x ≤ 500)
begin
x:=2x ;
i:=i+1;
end
What is the value of i at the end of the pseudocode?
 A 4 B 5 C 6 D 7
Data-Structures       Programming       ISRO CS 2011
Question 6 Explanation:
After completion of first iteration x and i values are : x = 2 and i = 2
After completion of second iteration x and i values are : x = 4 and i = 3
After completion of third iteration x and i values are : x = 16 and i = 4
After completion of fourth iteration x and i values are : x =256 and i = 5
After completion of fifth iteration x and i values are : x = 65536 and i = 6(Condition is false)
Then the value of “i” is 5
 Question 7

What is the output of the following C code?

#include

int main()

{

int index;

for(index=1; index<=5; index++)

{

printf("%d", index);

if (index==3)

continue;

}

}

 A 1245 B 12345 C 12245 D 12354
Programming-for-Output-Problems       Programming       ISRO CS 2011
Question 7 Explanation:
The continue statement is used inside loops. When a continue statement is encountered inside a loop, control jumps to the beginning of the loop for next iteration, skipping the execution of statements inside the body of loop for the current iteration.
In the given code, there are no statements after continue statement , So it won’t effect on the output.
The loop will executes for five iterations,For each iteration it will print corresponding value i.e; 12345.
 Question 8
The following steps in a linked list
p = getnode()
info (p) = 10
next (p) = list
list = p
result in which type of operation?
 A pop operation in stack B removal of a node C inserting a node D modifying an existing node
Data-Structures       Programming       ISRO CS 2013
Question 8 Explanation:
p = getnode() // Allocating memory for node and starting address of that node will store in the pointer “p”
info (p) = 10 // Storing the value of 10 into the info field of new node
next (p) = list // adding new node to the existing list.
list=p // the starting address of the list will
point to the new node
 Question 9
Consider the following C code.
#include
#include
void main()
{
double pi = 3.1415926535;
int a = 1;
int i;
for(i=0; i < 3; i++)
if(a = cos(pi * i/2) )
printf("%d ",1);
else printf("%d ", 0);
}
What would the program print?
 A 000 B 010 C 101 D 111
Programming-for-Output-Problems       Programming       ISRO CS 2013
Question 9 Explanation:
→The for loop will execute three times for a given i values 0,1,2.
→For a given i = 0:
a = cos(pi * 0/2) [ PI*0 is 0]
a = cos(0) = 1, if condition true and it will print 1
→For a given i = 1
a = cos (pi/2) [pi*1 is pi]
a=cos(1.57075) whose value approximately equal to zero
a = 0, Here the condition is false then else part will execute and it will print 0
→For i = 2
a = cos(pi) [pi*2/2 is nothing but pi]
a = -1, ,Here also condition is true and it will execute if part and it will print “1”
→Finally it will print 101.
 Question 10
What is the output of the following Java program?
Class Test
{
public static void main (String [] args)
{
int x = 0;
int y = 0;
for (int z = 0; z < 5; z++)
{
if((++x > 2) || (++y > 2))
{
x++;
}
}
System.out.println( x + " " + y);
}
}
 A 8 2 B 8 5 C 8 3 D 5 3
Java       Programming       ISRO CS 2013
Question 10 Explanation:
Initial values of x and y is 0
For the given code, the loop will execute 5 times.
Step-1: For z = 0,
The following condition will execute
if((++x > 2) || (++y > 2))
Here pre-increment operation will be performed on x and y. Then x and y values are 1 and the condition false
Similar operation will be performed for z values 1,2,3 and 4
Step-2: For z = 1, Then x and y values become 2 and the condition false.
Step-3: For z = 2, “||” operator is present in the expression, if first operand is true then no need to check the second operand.x value is 3, if condition true and ++y is not evaluated,again “x” value is incremented then x value is “4”.
Perform the step-3 procedure for z value 3 and 4 . Here x value is incremented “4” times. Then the final value of “x” is 8 and “y” is 2.
 Question 11
Consider the following pseudocode: x : integer := 1 y : integer := 2 procedure add x := x + y procedure second (P: procedure) x : integer := 2 P() procedure first y : integer := 3 second(add) first() write_integer (x) What does it print if the language uses dynamic scoping with deep binding?
 A 2 B 3 C 4 D 5
Data-Structures       Programming       ISRO CS 2013
Question 11 Explanation:
Scope rule:
The “current” binding for a given name is the one encountered most recently during execution
Dynamic scoping :
The scope of bindings is determined at run time not at Compile time .
→ For deep binding, the referencing environment is bundled with the subroutine as a closure and passed as an argument. A subroutine closure contains
– A pointer to the subroutine code
– The current set of name-to-object bindings
→ By considering dynamic scoping with deep binding when add is passed into second the environment is x = 1, y = 3 and the x is the global x so it writes 4 into the global x, which is the one picked up by the write_integer.
 Question 12

Consider the following pseudo-code fragment, where m is a non-negative integer that has been initialized:

p = 0;
k = 0;
while(k < m)
p = p + 2k;
k = k + 1;
end while

Which of the following is a loop invariant for the while statement?

(Note: a loop variant for a while statement is an assertion that is true each time guard is evaluated during the execution of the while statement).

Options:
 A p = 2k - 1 and 0≤k B p = 2k+1 - 1 and 0≤k C p = 2k - 1 and 0≤k≤m D p = 2k+1 - 1 and 0≤k≤m
Programming       programming       UGC-NET DEC Paper-2
Question 12 Explanation:
For k=0, P = 0+20 = 1
k=1, P = 1+21 = 3
k=2, P = 3+22 = 7
k=3, P = 7+23 = 15
Only the option-3 satisfied to the loop variant.
Ex: m=2, The loop will execute for 3 times for k value is 0,1 and 2.
Then options-3 gives P=1, P=3 and P=7 for the k values 0,1 and respectively.
 Question 13

Consider the C/C++ function f() given below:

void f(char w [])
{
int x = strlen(w);  //length of a string
char c;
For (int i = 0; i < x; i++)
{
c = w[i];
w[i] = w[x - i - 1];
w[x - i - 1] = c;
}
}

Which of the following is the purpose of f() ?

 A It output the content of the array with the characters rearranged so they are no longer recognized a the words in the original phrase. B It output the contents of the array with the characters shifted over by one position. C It outputs the contents of the array in the original order. D It outputs the contents of the array in the reverse order.
Programming-in-C/C++       Programming       UGC-NET DEC Paper-2
Question 13 Explanation:
It outputs the contents of the array in the original order because it swaps pairs of elements at locations (i and x - i - 1) twice.
 Question 14

Consider the following two C++ programs P1 and P2 and two statements S1 and S2 about the programs : S1: P1 prints out 3
S2: P2 prints out 4:2

What can you say about the statement S1 and S2 ?

Code:
 A Neither S1 nor S2 is true B Only S1 is true C Only S2 is true D Both S1 and S2 are true
Programming-in-C++       Programming       UGC-NET DEC Paper-2
Question 14 Explanation:
The program P1 code consists of function with three parameters integer, pointer and reference variable.
The definition of the function first modifies “i” value by 2 and later by “3” and that modification of the value is automatically reflects in the main program as “c” is reference variable.
The program code P2 will gives the output of 4:5 as the function will take reference variable as parameter and return type also reference object.
 Question 15

What does the following java function perform ? (Assume int occupies four bytes of storage)

Public static int f(int a)
{
//Pre-conditions : a>0 and no overflow/underflow occurs
int b=0;
for(int i=0; i<32; i++)
{
b=b <<1;
b= b | (a & 1);
a = a >>> 1; // This is a logical shift
}
Return b;
}
 A Return the int that represents the number of 0’s in the binary representation of integer a. B Return the int that represents the number of 1’s in the binary representation of integer a. C Return the int that has the reversed binary representation of integer a. D Return the int that has the binary representation of integer a.
JAVA       Programming       UGC-NET DEC Paper-2
Question 15 Explanation:
→ Consider the a value is 5.
The initial value of b is 0 and b<<1 means b will get value of 2
b=b|(a&1) which means 2|(5&1) then b will get value “2”
a=a<<1 means value a will reduce to 3
→ Repeat the above procedure for 31 iterations.
→ Iteration-2: b=b<<1 then b is 4 and b=b|(a&1)= 4|(3&1) then b is 5 and a becomes 1
→ Iteration-3: b=b<<1 then b is 10 and b=b|(1&1) = 4|(3&1) then b is 11 and a becomes 0
→ And this procedure will repeat until “i” value is 32.
→ The final value is 11 (Number of 1’s in the result is 2) and the number of 1’s in the input 5 are 2.
 Question 16

Consider the following recursive Java function f that takes two long arguments and returns a float value :

public static float f(long m, long n)
{
float result = (float) m / (float) n;
if (m < 0 || n < 0)
return 0⋅0f;
else
result += f(m*2, n*3);
result result;
}

Which of the following integers best approximates the value of f(2,3) ?

 A 0 B 3 C 1 D 2
JAVA       Programming       UGC-NET DEC Paper-2
 Question 17

Consider the following method :

int f(int m, int n, boolean x, boolean y)
{
int res=0;
if(m<0) {res=n-m;}
else if(x || y) {
res= -1;
if( n==m) { res =1; }
}
else {res=n; }
return res;
} /*end of f */

If P is the minimum number of tests to achieve full statement coverage for f() and Q is the minimum number of tests to achieve full branch coverage for f(), then (P,Q) =

 A (3,4) B (3,2) C (2,3) D (4,3)
Programming       Programming       UGC-NET DEC Paper-2
Question 17 Explanation:
→ Code coverage is a measure which describes the degree of which the source code of the program has been tested.
→ Statement coverage is a white box test design technique which involves execution of all the executable statements in the source code at least once. It is used to calculate and measure the number of statements in the source code which can be executed given the requirements.
→ Branch coverage is a testing method, which aims to ensure that each one of the possible branch from each decision point is executed at least once and thereby ensuring that all reachable code is executed.
→ In the branch coverage, every outcome from a code module is tested. For example, if the outcomes are binary, you need to test both True and False outcomes.
 Question 18
The following ‘C’ statement : int *f [ ] ( ); declares:
 A A function returning a pointer to an array of integers. B Array of functions returning pointers to integers. C A function returning an array of pointers to integers. D An illegal statement.
Programming       Programming       UGC NET CS 2016 Aug- paper-2
Question 18 Explanation:
int *f [ ] ( ); It declares array of functions returning pointers to integers.
 Question 19
Given i = 0, j = 1, k = –1 x = 0.5, y = 0.0 What is the output of the following expression in C language ?
x * y < i + j || k
 A -1 B 0 C 1 D 2
Programming       Programming       UGC NET CS 2016 July- paper-2
Question 19 Explanation:
x * y < i + j || k
Step-1: Evaluate x * y because multiplication has more priority than remaining operators
x * y→ 0
Step-2: i + j is 1
Step-3: (x*y) < (i+j) is 1. Because relational operators only return 1(TRUE) or 0(FALSE).
Step-4: ((x*y) < (i+j)) || k is logical OR operator.
1 || -1 will returns 1.
Note: The precedence is ((x*y) < (i+j)) || k
 Question 20
What is the value returned by the function f given below when n = 100?
int f (int n)
{
if (n = = 0) then return n;
else return n + f(n-2);
}
 A 2550 B 2556 C 5220 D 5520
Programming       Programming       UGC NET CS 2016 July- paper-2
Question 20 Explanation:
Given n=100
Step-1: int f(100)
{ if (100 = = 0) then return 100; /*false*/
else return 100 + f(100-2); /* return 198 */
}
Step-2: int f(98)
{ if (98 = = 0) then return 98; /*false*/
else return 98 + f(96); /* return 194 */
}
Step-3: int f(96)
{ if (96 = = 0) then return 96; /*false*/
else return 96 + f(94); /* return 190 */
}
;
;
Step-final:
int f(0)
{ if (0 = = 0) then return 0; /*TRUE*/
else return 0 + f(0); /* FALSE */
}
Actual process:
The above series is nothing but sum of Arithmetic Progression(A.P)
= 2+4+6+8+ ... +98+100
= n(n+1)
/* It is nothing but sum of even numbers upto 'n' */
= 50*51
= 2550
 Question 21
Consider the following program :
#include
main( )
{
int i, inp;
float x, term=1, sum=0;
scanf(“%d %f ”, &inp, &x);
for(i=1; i<=inp; i++)
{
term = term * x/i;
sum = sum + term ;
}
printf(“Result = %f\n”, sum);
}
The program computes the sum of which of the following series?
 A x + x​ 2​ /2 + x​ 3​ /3 + x​ 4​ /4 +... B x + x​ 2​ /2! + x​ 3​ /3! + x​ 4​ /4! +... C 1 + x​ 2​ /2 + x​ 3​ /3 + x​ 4​ /4 +... D 1 + x​ 2​ /2! + x​ 3​ /3! + x​ 4​ /4! +...
Programming       Programming       UGC NET CS 2015 Dec- paper-2
Question 21 Explanation:
In this problem, we have to find series of evaluation.
Let x=5, inp=5
Iteration-1:
for(i=1; i<=inp; i++)
/* condition true 1<=5 */
{
term = term * x/i;
/* (1*5)/1=5. Here, 5 nothing but ‘x’ */
sum = sum + term ; /* 0+5=5 */
}
Iteration-2: Here, ‘i’ becomes 2.
for(i=2; i<=inp; i++)
/* condition true 2<=5 */
{
term = term * x/i;
/* (5*5)/2 is nothing but x​ 2​ /i */
sum = sum + term ; /* 5+12=17 */
}
;;;
;;;
Iteration-5: Here, ‘i’ becomes 5.
for(i=5; i<=inp; i++)
/* condition true 5<=5 */
{
term = term * x/i;
/* (625*5)/5! is nothing but x​ 5​ /i! */
sum = sum + term ;
}
So, Option-B is correct answer.
 Question 22
What will be the output of the following ‘C’ code ?
main( )
{
int x=128;
printf (“\n%d”, 1 + x++);
}
 A 128 B 129 C 130 D 131
Programming       Programming       UGC NET CS 2014 Dec-Paper-2
Question 22 Explanation:
In this program we are using post increment. Post increment will send the value before updating the value.
printf(“\n%d”, 1 + x++); /* x=128 */
Here, 1+128=129
 Question 23
What does the following expression means ? char *(*(*a[N]) ( )) ( );
 A a pointer to a function returning array of n pointers to function returning character pointers. B a function return array of N pointers to functions returning pointers to characters C an array of n pointers to function returning pointers to characters D an array of n pointers to function returning pointers to functions returning pointers to characters.
Programming       Programming       UGC NET CS 2014 Dec-Paper-2
Question 23 Explanation:
char *(*(*a[N]) ( )) ( ); /* an array of n pointers to function returning pointers to functions returning pointers to characters */
 Question 24
Consider the following pseudo-code fragment, where m is a non-negative integer that has been initialized:
p=0;
k=0;
while(k < m)
p = p + 2k;
k=k+1;
end while
Which of the following is a loop invariant for the while statement?
(Note: a loop variant for a while statement is an assertion that is true each time guard is evaluated during the execution of the while statement).
 A p = 2 k − 1 and 0≤k < m B p = 2 k+1 − 1 and 0≤k < m C p = 2 k − 1 and 0≤k≤m D p = 2 k+1 − 1 and 0≤k≤m
Programming       Programming       UGC NET CS 2018-DEC Paper-2
Question 24 Explanation:
For k=0, P=0+2​ 0​ =1
k=1, P=1+2​ 1​ =3
k=2,P=3+2​ 2​ =7
k=3,P=7+2​ 3​ =15
Only the option-3 satisfied to the loop variant.
Ex: m=2, The loop will execute for 3 times for k value is 0,1 and 2.
Then options-3 gives P=1,P=3 and P=7 for the k values 0,1 and respectively
 Question 25
Consider the C/C++ function f() given below:
void f(char w [ ] )
{
int x = strlen(w); //length of a string
char c;
For (int i = 0; i < x; i++)
{
c = w[i];
w[i] = w[x - i - 1];
w[x - i - 1] = c;
}
}
Which of the following is the purpose of f() ?
 A It output the content of the array with the characters rearranged so they are no longer recognized a the words in the original phrase. B It output the contents of the array with the characters shifted over by one position. C It outputs the contents of the array in the original order. D It outputs the contents of the array in the reverse order.
programming       programming       UGC NET CS 2018-DEC Paper-2
Question 25 Explanation:
It outputs the contents of the array in the original order because it swaps pairs of elements at locations (i and x - i - 1) twice .
 Question 26
What does the following java function perform ? (Assume int occupies four bytes of storage)
Public static int f(int a)
{
//Pre-conditions : a>0 and no overflow/underflow occurs
int b=0;
for(int i=0; i<32; i++)
{
b=b <<1;
b= b | (a & 1);
a = a >>> 1; // This is a logical shift
}
Return b;
}
 A Return the int that represents the number of 0’s in the binary representation of integer a. B Return the int that represents the number of 1’s in the binary representation of integer a. C Return the int that has the reversed binary representation of integer a. D Return the int that has the binary representation of integer a.
Programming       Programming       UGC NET CS 2018-DEC Paper-2
Question 26 Explanation:
→ Consider the a value is 5 .
The initial value of b is 0 and b<<1 means b will get value of 2
b=b|(a&1) which means 2|(5&1) then b will get value “2”
a=a<<1 means value a will reduce to 3
→ Repeat the above procedure for 31 iterations .
→ Iteration-2: b=b<<1 then b is 4 and b=b|(a&1)= 4|(3&1) then b is 5 and a becomes 1
→ Iteration-3: b=b<<1 then b is 10 and b=b|(1&1)= 4|(3&1) then b is 11 and a becomes 0
→ And this procedure will repeat until “i” value is 32.
→ The final value is 11 (Number of 1’s in the result is 2) and the number of 1’s in the input 5 are 2.
 Question 27
Consider the following recursive Java function f that takes two long arguments and returns a float value :
public static float f(long m, long n)
{
float result = (float) m / (float) n;
if (m < 0 || n < 0)
return 0⋅0f;
else
result += f(m*2, n*3);
result result;
}
Which of the following integers best approximates the value of f(2,3) ?
 A 0 B 3 C 1 D 2
Programming       Programming       UGC NET CS 2018-DEC Paper-2
Question 27 Explanation:
public static float f(long m, long n)
{
float result = (float) m / (float) n;
if (m < 0 || n < 0)
return 0⋅0f;
else
result += f(m*2, n*3);
result result;
}
function call→ f(2,3)
→ result=2.0/3.0
=0.666
if condition is false, else will be executed result = 0.666+f(4,9) function call→ f(4,9)
→ result=4.0/9.0
=0.444
result=0.4444+f(8,27)
function call→ f(8,27)
→ result=8.0/27.0
=0.2962
result=0.2962+f(16,54)
function call→ f(16,81)
→ result=16.0/81.0
=0.1975
result=0.1975+f(32,243)
function call→ f(32,243)
→ result= 32.0/243.0
= 0.13168
result=0.13168+f(64,729)
and so on
f(128,2187),f(256,6561),f(512,19683),f(1024,59049),f(2048,177147)
result=0.6666+0.4444+0.2962+0.1975+0.13168+0.08779+0.0390+0.026+0.0173+0.0115
The best approximate value is sum of all the function call result values which is equal 2.
 Question 28
Consider the following method :
int f(int m, int n, boolean x, boolean y)
{
int res=0;
if(m<0) {res=n-m;}
else if(x || y) {
res= -1;
if( n==m) { res =1; }
}
else {res=n; }
return res;
} /*end of f */
If P is the minimum number of tests to achieve full statement coverage for f() and Q is the minimum number of tests to achieve full branch coverage for f(), then (P,Q) =
 A (3,4) B (3,2) C (2,3) D (4,3)
Programming       Programming       UGC NET CS 2018-DEC Paper-2
Question 28 Explanation:
→ Code coverage is a measure which describes the degree of which the source code of the program has been tested
→ Statement coverage is a white box test design technique which involves execution of all the executable statements in the source code at least once. It is used to calculate and measure the number of statements in the source code which can be executed given the requirements.
→ Branch coverage is a testing method, which aims to ensure that each one of the possible branch from each decision point is executed at least once and thereby ensuring that all reachable code is executed.
→ In the branch coverage, every outcome from a code module is tested. For example, if the outcomes are binary, you need to test both True and False outcomes.
There are 28 questions to complete.
PHP Code Snippets Powered By : XYZScripts.com