Page 335 - Computer science 868 Class 12
P. 335
while(dividend<=N)
{
for(i=2;i<dividend; i++)
{
if(dividend %i==0)
{
break;
}
if(i==dividend-1)
{
ar[j++]=dividend;
}
}
dividend++;
}
System.out.println(ar);
}
4. The following functions are the parts of some class:
void fun1 (char s[],int x)
{
System.out.println(s);
char 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<c.length; i++)
c[i]=n.charAt(i);
fun1(c,0);
}
(i) What will be the output of fun1() when the value of s[]={‘J’,‘U’,‘N’,‘E’} and x = 1?
(ii) What will be the output of fun2() when the value of n = ‘SCROLL”?
(iii) State in one line what the function fun1() does apart from recursion.
5. The following is a function of some class that sorts an integer array a[] in ascending order using the selection sort technique.
There are some places in the code marked by ?1?, ?2?, ?3?, ?4?, ?5? which may be replaced by some statements/expressions so
that the function works properly.
void selectsort(int []a)
{
int i, j, t, min, minpos;
for(i=0;i {
min=a[i];
minpos = i;
for(j=?2?;y<a.length;j++) { if(min>a[j])
{
?3?=j;
min = ?4?;
}
}
t=a[minpos];
a[minpos]=a[i];
a[i]= ?5?;
}
333
Arrays 333

