Consider the following C program :
#include <stdio.h> int g(int n) { return (n+10); } int f(int n) { return g(n*2); } int main() { int sum, n; sum=0; for (n=1; n<3; n++) sum += g(f(n)); printf("%d", sum); return 0; }
The output of the given C program is ________. (Answer in integer)
#include <stdio.h>
int foo(int S[ ], int size) {
if(size == 0) return 0;
if(size == 1) return 1;
if(S[0]!=S[1]) return 1 + foo(S + 1, size - 1);
return foo(S + 1, size - 1);
}
int main( ) {
int A[] ={0,1,2,2,2,0,0,1,1};
printf("%d", foo(A, 9));
return 0;
}
The value printed by the given C program is _________. (Answer in integer)
Consider the following C program :
#include < stdio.h>
int gate (int n) {
int d, t, newnum, turn;
newnum = turn = 0; t=1;
while (n>= t) t*= 10;
t/=10;
while (t>0) {
d=n/t;
n=n%t;
t/= 10;
if (turn) newnum = 10*newnum + d;
turn = (turn + 1) % 2;
}
return newnum;
}
int main( ) {
printf("%d", gate(14362));
return 0;
}
The value printed by the given C program is _________. (Answer in integer)
Consider an array X that contains n positive integers. A subarray of X is defined to be a sequence of array locations with consecutive indices.
The C code snippet given below has been written to compute the length of the longest subarray of X that contains at most two distinct integers. The code has two missing expressions labelled (P) and (Q).
int first=0, second=0, len1=0, len2=0, maxlen=0; for (int i=0; i < n; i++) { if (X[i] == first) { len2++; len1++; } else if (X[i] == second) { len2++; len1 = (P); second = first; } else { len2 = (Q); len1 = 1; second = first; } if (len2 > maxlen) { maxlen = len2; } first = X[i]; }
Which one of the following options gives the CORRECT missing expressions?
(Hint: At the end of the i-th iteration, the value of len1 is the length of the longest subarray ending with X[i] that contains all equal values, and len2 is the length of the longest subarray ending with X[i] that contains at most two distinct values.)