You are on page 1of 10

Outputs of class XII

1. The following function check() is a part of some class. What will be the function check() return when the value of
i) n=25 ii) n=10. Show the dry run/working. [2020]
int check(int n)
{
if(n<=1)
retur 1;
if(n%2==0)
return 1 + check(n/2);
else return 1 + check(n/2 + 1);
}

2. The following function Mystery() is a part of some class. What will the fucntion Mystery() return the value of
num=43629, x=3 and y=4 repectively? Show the dry run/working. [2019]
int Mystery(int num, int x, int y)
{
if(num<10)
return num;
else
{
int z=num%10;
if(z%2==0)
return z*x + Mystery (num/10,x,y);
else
return z*y + Mystery(num/10,x,y);
}
}
3. The following is a function of some class which checks if a positive integer is an Palindrome number by returning
true or false. (A number is said to be palindrome number if the reverse of the number is equal to the original number).
The function does not use modulus (%) operator to extract digits. There are some places in the code marked by
?1?,?2?,?3?,?4?,?5? which may be replaced by a statement/expression so that the function. [2018]
boolean PalindromeNum(int N)
{
int rev=?1?;
int num=N;
while(num>0)
{
int f=num/10;
int s= ?2?;
int digit=num-?3?;
rev=?4?+digit;
num/=?5?;
}
if(rev==N)
return true;
else return false;
}
4. The following function magicfun () is a part of some class. What will the function magicflun() return when value of
‘n’ =7 and n=10 respectively ? Show the dry run/working. [2017]
int magicfun(int m, int n)
{
if( n==0)
retrun 0;
else
retrun magicfun(n/2)*10+(n%2);
}
5.
6. The following function Check () is a part of some class. What will the function Check() return when values of both
‘m’ and ‘n’ are equal to 5? Show the dry run/working. [2016]
int Check(int m, int n)
{
if( n==1)
retrun –m--;
else
retrun ++m + Check(m, --n);
}

7. The following function is a part of some class. Assume that ‘x’ and ‘y’ are positive integers, greater than 0. Answer
the given questions along with dry run/working. [2015]
void sumeFun(int x, int y)
{
if(x>1)
{
if(x%y==0)
{
System.out.print(y+” ”);
someFun(x/y,y);
}
else
someFun(x,y+1);
}
}
i) What will be returned by someFun(24,2)?
ii) What will be returned by someFun(84,2)?
iii) State in one line what does the function someFun() do, apart from recursion?

8. The following is a function of some class which checks if a positive integer is an Amstrong number by returning
true or false. (A number is said to be Armstrong number if the sum of the cubes of all its digits is equal to the original
number). The function does not use modulus (%) operator to extract digits. There are some places in the code marked by
?1?,?2?,?3?,?4?,?5? which may be replaced by a statement/expression so that the function. [2015]
boolean Armstron(int n)
{
int sum=?1?;
int num=N;
while(num>0)
{
int f=num/10;
int s= ?2?;
int digit=num-s;
sum+=?3?;
num=?4?;
}
if(?5?)
return true;
else return false;
}
9. The following function is of some class which sorts an integer array a[] in ascending order using selection sorting
technique. There are some places in the code marked by ?1?,?2?,?3?,?4?,?5? which may be replaced by a
statement/expression so that the function: [2014]
void selectsort(int [] a)
{
int i,j,t,min,minpos;
for(i=0;i<?1?;i++)
{min=a[i];
minpos=i;
for(j=?2?;j<a.length;j++)
{
if(min>a[j])
{
?3?=j;
min=?4?;
}
t=a[minpos];
a[minpos]=a[i];
a[i]=?5?;
}
for(int k=0;k<a.length;k++)
System.out.println(a[k]);
}
10. The following function is a part of some class. [2014]
void fun1(char s[], int x)
{
System.out.println(s);
int temp;
if(x<s.length/2)
{
temp=s[x];
s[x]=s[s.length-x-1];
s[s.length-x-1]=temp;
fun1(s,x+1);
}
}
void fun2(String n)
{
char c[]=new char[n.length()];
for(int i=0;i<n.length();i++)
c[i]=n.charAt(i);
fun1(c,0);
}

i) What will be output of fun1() when the value of s[]={‘J’,’U’,’N’,’E’} and x=1
ii) What will be output of fun2() when the value of n=”SCROLL”
iii) State in one line what does the function fun1() do apart from recursion?
11. The following functin Recur() is a part of some class. What does the output of the fucntion Recur() when the value of n
is equal to 10. Show dry run/working. [2013]
void Recur(int n)
{
if(n>1)
{
System.out.print(n+” ”);
if(n%2!=0)
{
n=3*n+1;
System.out.print(n+” ”);
}
recur(n/2);
}
}
12. The following function is a part of some class. Assume ‘n’ is a positive integer. Answer the given questions along
with dry run/working: [2013]
int unknown( int n)
{
int i,k;
if(n%2==0)
{
i=n/2;
k=1;
}
else
{
k=n;
n--;
i=n/2;
}
while(i>0)
{
k=k*i*n;
i--;
n--;
}
return k;
}
i) What will be returned by the function unknown(5)?
ii) What will be returned by the functon unknown(6)?
iii) What is being computed by the function unknown(int n)?
13. The following function is of some class which sorts an integer array a[] in ascending order using Bubble sorting
technique. There are some places in the code markes by ?1?,?2?,?3?,?4?,?5? which may be replaced by a
statement/expression so that the function: [2012]
void Bubsort(int arr[])
{
int i,j,k,temp;
for(i=0;?1?;i++)
{
for(j=0;?2?;j++)
{
if(arr[j]>?3?)
{
temp=arr[j];
?4?=arr[j+1];
arr[j+1]=?5?;
}}}}
14. The following function witty() is a part of some class. What will be the output of witty() when value of
n=”SCIENCE”and p=5. Show dry run/working. [2012]
void witty(String n, int p)
{
if(p<0)
System.out.println(“”);
else
{
System.out.println(n.charAt(p)+”.”);
witty(n,p-1);
System.out.println(n.charAt(p-1));
}
}
15. The following function mymethod() is a part of some class. What will be the output of witty() when value of
counter is 3? Show dry run/working. [2011]
void mymethod(int counter)
{
if(counter==0)
System.out.println(“ ”);
else
{
System.out.println(“Hello”+counter);
Mymehod(--counter)
System.out.println(“ ”+counter);
}
}
16. The following function is of some class which computes and returns the GCD of two number in the code marked by
?1?,?2?,?3?,?4?,?5? which may be replaced by a statement/expression so that the function:
[2011]
int gcd(int a,int b)
{
int r;
while(?1?)
{
r=?2?;
b=?3?;
a=?4?;
}
if(a==0)
return ?5?;
else
return -1;
}
17. The following function is of some class which checks wheter a number is perfect or not marked by ?1?,?2?,?3?,?4?,?5?
which may be replaced by a statement/expression so that the function:

void perfect(int n)
{
int s=?1?;
for(int a=1;a<n;a++)
{
if(n%?2?==0)
s+=?3?;
}
if(?4?==?5?)
System.out.println(n+”is perfect number”);
else
System.out.prinltn(n+”is not a perfect number”);
}
18. Following is a public member function of some class written in to do binary search. Assume that data[] is in ascending
order. If m is present in the data[] it returns 1 else returns 0. There are five places markd by ?1?,?2?,?3?,?4?,?5? which
may be replaced by a statement/expression so that the function:
int search(int m,int data[],int size)
{
int found=0;
int j=0,k=?1?;
if(?2?)
{
while(?3?)
{
int i=(j+k)/2;
if(m==data[i])
{
?4?;
break;
)
else
{
if(?5?)
j=i+1;
else
k=i-1;
}}}
return (found);
}
19. The following function is the member of some class. Answer the questions given after the funciton. Show dry
run/working:
float profun(int x, int y)
{
float r=1.0f; int ch=0;
if(y==0)
return r;
if(y<0)
{
y=y*(-1);
ch=1;
}
for(int m=1;m<=y;m++)
r*=x;
if(ch==1)
r=1/r;
retrun r;
}
a) What is returned by the Profun(2,3)?
b) What is returned by the Profun(4,0)?
c) What is returned by the Profun(2,-3)?
d) State in one line as computed by the funcion Profun()?
20. The following function is the member of some class. Answer the questions given after the funciton. Show dry
run/working:
int somefn(int a, int b)
{
while(a!=b)
{
a-=b;
else
b-=a;
}
return a;
}
a) What is returned by the somefn(12,30)?
b) What is returned by the somefn(8,15)?
c) State in one line as computed by the funcion somefn()?
21. State the final value of s. show dry run/working:
int c,s=0;
for(int a=2;a<5;++a)
{
for(int b=1;b<a;++b)
{
c=a+b-1;
if(c%3==0)
s+=c;
else
s+=c+5;
}
}
22. Give the output of the following program:
void main()
{
int x=0;
do{
if(x<3)
{
x+=2;
System.out.println(x+”\t”);
continue;
}
else
{
System.out.println(++x);
break;
}
}
while(x<10);
}
23. The following function number(int ) and number1(int) are part of some class. Answe the questions given below show
dry run/working:
public void numbers(int n)
{
if(n>0)
{
System.out.print(n+” ”);
numbers(n-2);
System.out.print(n+” ”);
}
}
public String numbers1(int n)
{
if(n<=0)
retrun “”;
return (numbers(n-1)+n+” ”);
}
a) What will be the output of the funcion numbers( int n) when n=5?
b) What will be the output of the function numbers1( int n) when n=6
c) State in one line what is the function numbers1(int) doing apart from recursion.

24. The following function is of some class which sorts an integer array a[] in ascending order using Insertion sorting
technique. There are some places in the code marked by ?1?,?2?,?3?,?4?,?5? which may be replaced by a
statement/expression so that the function: [2010]
void insertionsort(int [] a)
{
int m=?1?;
int b,i,t;
for(i=?2?;i<m;i++){
t=a[i];
b=i-1;
While(?3?>=0 && t<a[b])
{
a[b+1]=a[b];
?4?;
}
?5?=t;
}
25. The following function trial() and perform() are part of some class. Answer the questions give below. Show dry
run/working:
int trial()
{
if(n==1)
return 2;
else if(n==2)
return 3;
else
return trial(n-2)+ trial(n-3);
}
void perform(int p)
{
int x;
for(int i=1;i<=p;i++)
{
x=trial(i);
System.out.print(x+” ”);
}
}
a) What will the function trial() return when n=4?
b) What will be the output of the function perform() when the value of p=5?
c) In one line state what the function trial() is doing apart from recursion?

26. The following funciton show() and calling() are parts of some class. Assume that the parameter n is greater than 1.
Show dry run/working:
void calling()
{
int f=2;
show(n,f);
}
int show(int n, int f)
{
if(n==f)
return 1;
if(n%f==0 || n==1)
return 0;
else
return(show(n,f+1));
}
a) What will be the function show() returns when calling() is invoked with n=11?
b) What will be the function show() returns when calling() is invokde with n=27?
c) State in one line, what the function show() executes?
27. The following function is of some class which computes x raised to the power n that belongs to a class. Here x is base
value and n is power. There are five places in the code marked by ?1?,?2?,?3?,?4?,?5? which may be replaced by a
statement/expression so that the function runs correctly.
double integralPower()
{
int inverse=0;double result=1.0;
if(n==0)
return ?1?;
else if(n<0)
{
inverse=1;n=?21?;
}
for(int i=1;?3?;i++)
result=?4?;
if(inverse==1)
result=?5?;
return result;
}
28. The following function is a part of some class. Answer the questions that followed the function:
void Task(int N)
{
if(N>0)
{
int d=N%2;
Task (n/2);
System.out.print (d);
}
}
a) What will be the output when function Taskl(9) is invoked?
b) What will be the output when function Taskl(7) is invoked?
c) In one line state what the function Taskl() is doing apart from recursion?

You might also like