Accenture specific
Pseudocode Questions
What will be the output of the following pseudocode?
integer val1, val2
set val1 = 5, val2 =7
result = val1 ^ val2
print result
What will be the output of the following code?
#include <stdio.h>
int main() {
int _._ = 30;
printf("%d", _._);
return 0;
}
What will be the output of the following code?
#include <stdio.h>
int main() {
int x = 5;
x <<= 3;
printf("%d", x);
return 0;
}
What will be the output of the following code?
#include <stdio.h>
int main() {
int a = 28; // 11100
int b = 0;
for(b;b<=3;++b)
printf(“The left shift obtained by %d: %d\n”, b, a<<b);
return 0;
}
What will be the output of the following code?
import static java.lang.System.*;
class _a
{
static public void main(String[] __A_V_)
{
String $ = "";
for (int x =0; ++x<__A_V_.length;)
$ += __A_V_[x];
out.println($);
}
}
And the command line: java _a - A .
What will be the output of the following pseudocode?
integer value , n
set value = 1, n = 45
while (value less than equal to n)
value = value << 1
end loop
print value
What will be the output of the following code?
#include<stdio.h>
int main()
{
int num1=10,num2 =3, num3 = 6;
int result = num1 & num2 | num3;
printf("%d",result);
return 0;
}
What will be the output of the following pseudocode?
set character ch =‘a’
set integer count = 0
while(ch > ’a’)
count++
ch- -
end while
display count
What will be the output of the following pseudocode?
integer val1, val2
set val1 = 16, val2 = 13
val2 = val1-2
do {
print val1
val1 = val2 + (val1-2)
}
while(val1<40)
End do while
What will be the output of the following pseudocode?
integer p, q, r
set p = 7, q = 4, r = 5
if( (p+r) < (q-p) ||r<p)
r = q&p
r = (r+3) & p
end if
print p+q+r
What will be the output of the following pseudocode?
#include <stdio.h>
int main()
{
int p=15, q=6, r= 4;
q = !p;
r != !!p;
printf("%d%d",q,r);
return 0;
}
What will be the output of the following pseudocode if
value of ta = 5 and tb = 7
integer func_sum (integer ta, integer tb)
ta = ta<<(ta-2)
tb = tb>>(tb-3)
ta = ta+2
tb = tb-1
return ta+tb
end function func_sum()
What will be the output of the following pseudocode?
integer p = 1, q = 2
for(integer i =0; i<=7; i+=2)
p = p+q+i
p = p+q
q = p-q
print q
end for
What will be the output of the following pseudocode?
integer m
for(m = 3;m!=0;m--)
Print m
m = m-1
end for
What will be the output of the following code?
int main()
int c = 5, no = 1000;
do
{
no /=c; // no = no/c
} while (c--);
printf(“%d\n”, no);
return 0;
}
What will be the output of the following code?
int main()
{
int a=10, b =20, c=30;
if(c>b>a)
print(“true”);
else
print(“false”);
return 0;
}
What will be the output of the following pseudocode?
integer pp, qq, rr
Set pp = 6, qq = 3, rr = 5
qq = 1 + rr
qq = 5 + qq
if (5 < rr OR (pp + rr ) > ( rr – pp ))
pp = ( 9 & 7 ) + PP
qq =5+qq
end if
Print pp +qq+rr
What will be the output of the following pseudocode?
Integer p, q, r
Set p = 2, q = 5
q = p +q
for(each r from q to 8 )
q=p 2
end for
If (p>q)2>2
q = 0;
else
q=1
end if
print p +q +r
What will be the output of the following pseudocode?
integer p, q, r
Set p = 1, q = 2, r = 7
r = (r+9) + q
p=p
q = (p +7)& r
r = 1 +r
print p +q + r
What will be the output of the following pseudocode?
n=1
int Myfunction(int n)
if(n>7)
print (n)
else
return (increment n by 1)
end Myfunction()
What will be the output of the following code?
#include <stdio.h>
int main()
{
int a, b;
a = -6 - - 6;
b = -3 - - ( - 3 );
printf("a = %d b = %d", a, b);
return 0;
}
What will be the output of the following code?
#include<stdio.h>
int main(){
int a;
a=015 + 0x71 +5;
printf("%d",a);
return 0;
}
What will be the output of the following ?
integer value, n
set value = 32, n = 1
while(value greater than equal to n)
value = value>>1
end loop
print value
=================
What will be the output of the following
pseudocode?
integer p, q, r, s
set p = 1, q = 2, r = 0
s = (p XOR q) OR (r|1)
print s
What will be the output of the following
code?
int fun(int num)
{
if(num<=0)
return 1;
else
return num * fun(num-1);
}
// calling the function
fun(4);
What will be the output of the following
code?
int main()
{
int b = 15+7*3-8*(4,5);
printf("%d",b);
return 0;
}
What will be the output of the following
code?
#include <stdio.h>
int main()
{
int j = 9;
int b = (j++, j++);
printf("%d%d",b,j);
}
What will be the output of the following
code?
#include <stdio.h>
int main()
{
int a= 5;
int b = 4*a+3*4<2?4:7;
printf("%d",b);
}
What will be the output of the following
pseudocode?
function fun(n)
if(n ==0) then
return 0
else
print(n)
return fun(n+1)
end if
end function fun()
// calling of function fun
fun(5)
What will be the output of the following
pseudocode?
function fun()
set a = 5
set b = 10
if((a>3) or b++>10) then
print (b)
else
print (a)
end if
return 0
end function fun()
What will be the output of the following
pseudocode?
P = 15 q = 4
integer trytosolve(integer p, int q)
while(q)
value = p MOD q
p=q
q = value
end while
return p
end function trytosolve()
What will be the output of the following
code?
#include <stdio.h>
int main()
{
int x = 10;
int *y, **z;
y = &x;
z = &y;
**z = 7;
printf("%d%d%d", x, *y, **z);
return 0;
}
What will be the output of the following
code?
int m = 2, c = 1;
int n, a,b,limit = 10;
while(c<limit)
{
for(int n = 1;n<m;++n)
{
a= m*m-n*n;
b = 2*m*n;
c = m*m +n*n;
If(c>limit)
break;
printf(“%d%d%d”,a,b,c);
}
m++
}}
What will be the output of the following
code?
#include<stdio.h>
int main()
{ int val = 4;
do{
val++;
++val;
}
while(val++>7);
printf(“%d”,val);
return 0;
}
What will be the output of the following
code?
# include<stdio.h>
int fun(int no)
{
static int count =0;
count = count +no;
return count;}
void main(){
int i, j;
for(i =0;i<=5;i++)
{j = fun(i);
printf("%d",j);}
}
What will be the output of the following
code?
enum A{one=1, two=9, three };
enum B{dog =1, cat, bird};
int main()
{
enum B x = three;
int m;
m = x;
printf("%d",m);
return 0;
}
What will be the output of the following
code?
#include <stdio.h>
#define hello
int main()
{
#ifdef hello
#define hi 4
#else
#define hi 5
#endif
printf("%d", hi);
return 0;
}
What will be the output of the following
pseudocode for a = 4, b = 4, c = 7 ?
Integer myfun(integer a, integer b, integer c)
for(each c from 3 to 5)
a = (c +c)^b
if((a+c) < (c+a))
b = (a +11) + c
else
c = b+b;
a=3+b
continue
endif
End for
Return a + b
What will be the output of the following
pseudocode?
integer p, q, r
set p = 6 , q = 4, r = 7
p = (r +5)+ p
if((q&r&p)< (p&6))
r = 3^r
q = q&q
endif
print p+q + r
What will be the output of the following
pseudocode for a = 7, b = 4?
integer myfun(integer a, integer b)
integer c
set c = a +a +b+b
b = c +c +b+b
a = b-a
return a + b
end function myfun()
What will be the output of the following
pseudocode?
integer a, b, c
set a = 4 , b = 9, c = 9
if(b&(c>>1))
a = a+1
endif
print a+b+c
What will be the output of the following
pseudocode if a = 5 and b = 2?
integer myfun (integer a, integer b)
if (a>0 && b > 0 )
return b+ myfun(a-2,b-1)
else
a = a^b
return a
endif
end myfun()
What will be the output of the following code ?
#include <stdio.h>
int main()
{
int a = 1, b = 2;
a += b -= a;
printf("%d%d", a, b);
return 0;
}
What will be the output of the following
pseudocode ?
integer a,b,c
set a = 0, b = 1, c = 2
if(b^c || a&b || a>>1)
c=9
a = b+c
else
c=1
a = a+c
endif
print a+b+c
What will be the output of the following
pseudocode ?
integer p, q, r
set p = 2, q = 3, r = 5
q = (q +10) + p
p = ( p +p ) + q
if((p & 8 & r )> (7 & p))
q = (r+5)&r
q = q ^p
endif
print p + q + r
What will be the output of the following
pseudocode ?
a = 7, b = 2, c = 8
If((b^a)<a && (2^7)<c)
a = b+c
Else
c = (4+12)+a
b = 11+a
print(a+b+c)
What will be the output of the following c code ?
#include <stdio.h>
int main () {
char ch;
if(ch= printf(" "))
{
printf ("%d”, ch);
printf ("no output");
}
else
{
printf("output");
}
return 0;
}
What will be the output of the following
pseudocode for a = 1 , b = 2 ?
integer myfun(integer a, integer b)
if(a<3 and b<4)
return myfun(a+1, b +1)
else
return a+b
end if
end function myfunction ()
What will be the output of the following
pseudocode for a = 2 , b = 6 ?
integer myfun(integer a, integer b)
if (a>0)
if(b>0)
return a+b+myfun(a+1, 0)+ myfun(a+2,0) + myfun(a+3,0 )
endif
endif
return a+b
end function myfun()
What will be the output of the following
pseudocode ?
integer p, q, r
set p = 3, q = 1, r = 2
if (p+ (2&2&2) AND q+(3&3&3) AND r+(2^2^2))
p = p-2
q=p
else
P=r
q = q^2
end if
print p +q +r
What will be the output of the following
pseudocode ?
integer p, q, r
set p = 7, q = 6, r = 4
if((q^p)<r)
if((8^r)+(7+p)>(q^p))
q = (12&11) ^q
else
q= 7 +q
endif
endif
r = 7 +p
print p +q +r
What will be the output of the following
pseudocode ?
integer p, q, r
set p = 5, q = 8, r = 6
If(q<r && (r&p)<p)
if((r-q) <(q+r))
p = q +r
Else
P = (5+10)&r
End if
r = (q&5)^p
Else
P = (9+7) +r
Endif
print p +q +r
What will be the output of the following
pseudocode ?
integer a, b, c
set a = 8, b = 3, c = 10
c = (b^b)+c
c = (c+c)+c
print a+b+c
What will be the output of the following
pseudocode ?
integer a, b, c
set a = 5, b = 2, c = 6
b = (a+6)^a
c=(1+3)&b
b = (9+7)+b
print a+b+c
What will be the output of the following
pseudocode ?
integer j
integer arr[4] = {0,2,0,3}
if(( arr[3] +5)<(7+arr[3]))
arr[0] = (12^12) & arr[1]
Endif
arr[0]= (5+6) + arr[2]
print arr[1] + arr[2]
What will be the output of the following
pseudocode if the value of a = 8, b = 7, c = 10?
integer myfun(integer a , Integer b, integer c )
for(each c from 4 to 5)
b = (8+2)+b
End for
return a+ b
What will be the output of the following
pseudocode?
integer j
integer arr[4] = {1,2,3,5}
arr[2] = (arr[1]& arr[0]) &arr[0]
for(each j from 4 to 5)
arr[j mod 3 = (arr[3]+3)+arr[2]
arr[j mod 3 = 4 + arr[1]
end for
print arr[2] + arr[3]
What will be the output of the following
pseudocode?
integer j
integer arr[4] = {3,1,4,2}
If((arr[2] & arr[0]& arr[3])<(6-arr[3]-arr[2]))
arr[1] = (arr[0]+5) + arr[0]
Endif
If((arr[0]+ arr[3])< arr[3])
arr[2] = 5+arr[1]
End if
Arr[2] = (arr[3] +4) + arr[3]
print arr[0] + arr[2]
What will be the output of the following
pseudocode?
Integer x, y
Set x = 18, y = 15
y=x–1
do{
Print x
x = y + (x – 2)
}
while(x < 36)
end do while
What will be the output of the following
pseudocode?
integer i, j, no
set no = 5
for (each i from 1 to no)
for (each j from 1 to i)
print i
end for
go to new line
end for
What will be the output of the following
pseudocode?
Integer b,c, d,e, f
C = 22, d = 52, e = 13
For(each b from 1 to 3)
f = (c+d)/e
if(f%13 ==0)
e = ((e+f)-(c-10)) + b
else
d = d+b+f
End for
Print e, d
What will be the value returned by given function
if n = 10 ?
int sum(int n)
{
if(n !=2)
return n+sum(n-2);
else
return n ;
}
What will be the output of the following
pseudocode?
Integer a, b, c
Set a = 1, b = 4, c = 1
If(a-1>b+5)
b = 1 + a +1
if(b)
a= 1 +b+1
end if
b = b+1
End if
Print a+b+c
What will be the output of the following
pseudocode?
Integer I , j, k , n, x
Set k = 1, j = 1, x = 4
For(each i from 1 to x )
Print k
J+=1
K+=1
i+=1
End for
What will be the output of the following
pseudocode?
integer x, y, z
x = -3, y = 0
if(y-2<2)
for(each z from 0 to (3-2))
x = x +(y-3)
end for
end if
if(1)
for (each z from 0 to (3-2))
x = x+(y+5)
end for
end if
print x +y
What will be the output of the following pseudocode
if str1 = SUPPORT, a = 0, b = 6?
void fun(char str1, int a, int b)
char temp
temp = str1[a]
str1[a] = str1[b-a]
str1[b-a] = temp
if (a Equals (b/2)
return
end if
fun(str1, a+1, b)
end function fun()
What will be the output of the depicted pseudo code
for a = 6, b = 4 and c = 6
integer myfun(integer a, integer b, integer c)
for (each c from 3 to 6)
b = c+b
end for
return a+b
What will be the output of the depicted
pseudocode ?
integer pp, qq, rr
set pp = 9, qq = 6, rr = 5
if(pp>qq && (rr+qq)<(qq-rr))
rr = (4+5) +pp
if((rr&7&qq)>(7&rr))
pp = (rr+pp)^rr
Else
pp = &&rr
End if
Else
rr = qq+rr
End if
rr = 12 + qq
print pp +qq + rr