Class XI Sample Practical File Computer
Class XI Sample Practical File Computer
import java.util.Scanner;
class Smith {
int s = 0;
while (n > 0) {
int r = n % 10;
s += r;
n = n / 10;
return s;
int c = 0;
c++;
return (c == 2);
System.out.println("Enter a number");
int n = sc.nextInt();
sc.close();
if (obj.isprime(n) == false) {
int totalSum = 0;
int p = 2;
while (n > 1) {
if (n % p == 0) {
totalSum += obj.sumOfDigits(p);
n = n / p;
} else
p++;
if (totalSum == sumofdig) {
System.out.println("Smith number");
} else {
else
OUTPUT:
Enter a number
666
Smith number
ALGORITHM
1. Start of algorithm.
2. Declare and store an integer entered from user to check whether it is a smith
number or not.
3. Create a new object and call the function sumOfDigits( int ) with the parameter
being the number entered to get the sum of digits of the number entered and
store it in a variable.
5. Inside the if block initialize a total sum to be 0 in the beginning. Also initialize p
as a counter to be 2 which holds value of next prime number for the prime
factorization of the number.
6. a) Start a while loop with condition that number entered should be greater than
1. b) If the number is divisible by the value of p then we add the sum of digits of
the value of p to the total sum by calling sumOfDigits function with the argument
p and adding the result to the total sum. Otherwise if it is not divisible, increment
p by 1. This continues till the number is greater than 1 and is kept inside while
loop.
7. Outside of the while loop after counting sum of digits of all prime factors, check
whether the total sum which holds the sum of digits of all prime factors, equals to
the sum of digits of the number calculated earlier.
9. End of algorithm.
factors
2.CODE
import java.util.Scanner;
int arr[];
int n;
Mixer(int nn) {
n = nn;
void accept() {
arr[i] = sc.nextInt();
}
Mixer mix(Mixer A) {
int k = 0;
temp.arr[i] = this.arr[i];
System.out.println(temp.arr[i]);
k++;
int ind = 0;
temp.arr[i] = A.arr[ind];
ind++;
return temp;
}
void display() {
System.out.println(arr[i]);
int a = sc.nextInt();
A.accept();
A.display();
int b = sc.nextInt();
B.accept();
B.display();
Mixer M = B.mix(A);
M.display();
}
}
OUTPUT:
Enter the number of elements for array A
3
9
ALGORITHM:
1. Start of algorithm.
2. Input the length of first array of integers, make an object and pass that value to
the constructor which initializes the instance variable for holding the length of the
array for that object.
3. Call the accept() method with that object created in step 2, which initializes the
array for the object and enters elements into the array from the user.
4. Call the display() method with that object created in step 2 which displays the
array elements to the user by looping over the array and printing the array
elements.
. 6. Now call the mix() function with the context of one object and pass the other
object created as an argument.
9. Call display() with the object above to display the merged array with all the
elements.
objects
Global variables –
mix() –
accept() –
display() –
main() –
Returned
3.CODE
import java.util.Scanner;
class Admission
Admission()
{
for(int i=0;i<100;i++)
Adno[i]=0;
for(int i=0;i<100;i++)
Adno[i]=sc.nextInt();
int m=(l+u)/2;
if(l<=u)
if(Adno[m]==v)
return 1;
else if(Adno[m]>v)
return binSearch(l,(m-1),v);
else
return binSearch((m+1),u,v);
}
else
return -1;
obj.fillArray();
int n=sc.nextInt();
if(obj.binSearch(0,99,n)==1)
else
ALGORITHM:
1. (a) Create the integer array of dimension 100 for storing admission numbers.
(b) Create a default constructor to assign the array elements with default initial
values.
2. In the fillArray() function, start a loop from i=0 and continue it till i<100 with
updation statement i++.
Input all the elements in ascending order from the user and store it in the array.
(a) The formal parameters l, u, v will store lower bound of array, upper bound of
array and the particular
(b) The middle index will be found using the formula [m=(l+u)/2].
(c) An if-else ladder will be made which will operate until l<=u. After the condition
gets false, -1 will be
returned to the main() function and the control will be shifted to main() function.
(d) In the if block, another if-else ladder will be created. The first if block will check
whether the middle
function.
(e) The second else-if block will check whether the middle element is greater than
the element to be
searched or not. If it is, then the element will be searched in the first half of the
array. The function will
(f) (e) The third else block will be operated when the middle element is lesser than
the element to be
searched. Then the element will be searched in the second half of the array. The
function will be again
(g) This process will continue until the element is found or the upper bound of the
array is exceeded by
(c) The element to be searched from the user will be stored in the variable n.
(d) The lower bound-0, the upper bound-99 and the element to be searched- n will
be sent to the
binSearch() function.
(e) If the value returned by the function is 1, then the message that the element is
present will be
displayed.
(f) If the value returned by the function is- 1, then the message that the element is
not present will be
displayed.
4.CODE:
import java.util.Scanner;
class Sentence
String s, a="",t;
int i,k=0,j=0;
String w[];
System.out.println("Enter a sentence");
s=sc.nextLine();
s=s+' ';
for(i=0;i<s.length();i++)
if(s.charAt(i)==' ')
k++;
w=new String[k];
for(i=0;i<s.length();i++)
if(s.charAt(i)==' ')
w[j]=a;
j++;
a="";
else
a=a+s.charAt(i);
for(i=0;i<k-1;i++)
for(j=0;j<k-i-1;j++)
if((int)w[j].charAt(0)>(int)w[j+1].charAt(0))
t=w[j];
w[j]=w[j+1];
w[j+1]=t;
for(i=0;i<k;i++)
System.out.print(w[i]+" ");
OUTPUT:
Enter a sentence
I live in Kolkata
I Kolkata in live
ALGORITHM:
1. Input a sentence from the user. Store it in the variable s and add an extra space
at the end of
the sentence.
2. Start a loop with (i=0) and continue till (i<s.length()). Extract each character of
the array inside
the loop and check in the if-block whether each character is a blank space or not.
If the
condition is true, then keep updating a counter variable which will count the
number of blank
3. The number of blank spaces stored in k will indicate the number of words in the
sentence.
Create a string array w[] with dimension k which will store the words of the
sentence.
4. Again create a loop from (i=0) and continue till (i<s.length()). Extract each
character of the array
inside the loop and check in the if- block whether each character is a blank space
or not. If the
condition is false, then in the else part, keep storing each extracted character in
the variable a to
form each word until a blank space is obtained. If the extracted character is a
blank space, then
store the word a in the array. Update the index of the array and initialize the
variable a with
(a) Create an outer loop from (i=0) and continue till (i<k-1).
(b) Create an inner loop from (j=0) and continue till (j<k-1-i).
(c) In the if-block, we will extract the first character of adjacent words stored in
the array and
take their ASCII value using implicit conversion. Using their ASCII value, we will
check
whether the character of the second word is greater than the first word. If so, then
we will
swap the words inside the array. In this way, all the words will be arranged in
ascending
6. After the process gets completed, we will print the words of the array with
blank spaces in
t String Temporary variable for swapping words in the Bubble sort method.
i int For computing index of characters in the sentence and also in the array.
j int For computing the index of characters in the words and also in the array.
class Circular_Prime
int i,f=0;
for(i=1;i<=n;i++)
if(n%i==0)
f++;
if(f==2)
return 1;
else
return 0;
int c=0,copy,d=0,n,r,f,flag=1,s;
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
n=sc.nextInt();
for(copy=n;copy!=0;copy=copy/10)
d++;
if(obj.prime(n)==1)
while(c!=n)
r=c%(int)(Math.pow(10,(d-1)));
f=c/(int)(Math.pow(10,(d-1)));
c=(r*10)+f;
s=obj.prime(c);
if(s==0)
flag=0;
break;
}
else
flag=0
if(flag==1)
else
OUTPUT:
Enter a number
131
ALGORITHM:
1. Start of algorithm.
a. If prime returns 1.
3. In main function.
a. Declare and initialize variables c (to store the no obtained after calculation) ,
copy (to calculate the
no of digits) , d (to store the no of digits) , r (to store the remainder) , f (to store
the quotient) , s (to call
the function) , flag (to be used a a count) and n (to input the number).
iv. Check whether the number obtained is prime or not by calling the function
Prime(int). If not prime
vi. Lastly check if flag is equal to one then number is circular prime and if not then
it is not a circular
prime number.
Prime(int):-
Main():-
copy int To assign itself the value of n and process with the extraction of its digits.
s int To call the function and check that the number obtained is prime or not.
flag int Used as a count variable to check that the condition has been satisfied
or not.
6.CODE:
import java.util.Scanner;
class Identity
int a[][],m,n,i,j,flag=1;
m=sc.nextInt();
n=sc.nextInt();
a=new int[m][n];
for(i=0;i<m;i++)
for(j=0;j<n;j++)
a[i][j]=sc.nextInt();
if(m==n)
if(m==n)
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(i==j)
if(a[i][j]!=1)
flag=0;
break;
}
else
if(a[i][j]!=0)
flag=0;
break;
else
flag=0;
if(flag==1)
else
}
OUTPUT:
Enter the dimensions of the matrix
10
ALGORITHM:-
1. Start of algorithm.
6. Check if i is equal to j.
a. If i==j , further check whether the element is equal to one or not and if not flag
will be 0 and then
b. If i!=j , check whether the element is equal to zero or not and if not flag will be
zero and then
7. After all the iterations are performed, outside the loop check whether flag is
equal to one or not.
8. End of algorithm.
7.CODE
import java.util.Scanner;
class Matrix
int a[][],i,j,k,t,m,n;
m=sc.nextInt();
n=sc.nextInt();
a=new int[m][n];
for(i=0;i<m;i++)
for(j=0;j<n;j++)
a[i][j]=sc.nextInt();
}
System.out.println("The source array is-");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
System.out.print(a[i][j]+"\t");
System.out.print("\n");
for(i=0;i<m;i++)
for(j=0;j<n-1;j++)
for(k=0;k<n-1-i;k++)
if(a[i][k]>a[i][k+1])
t=a[i][k];
a[i][k]=a[i][k+1];
a[i][k+1]=t;
}
}
for(i=0;i<m;i++)
for(j=0;j<n;j++)
System.out.print(a[i][j]+"\t");
System.out.print("\n");
OUTPUT:
Enter the row and column numbers respectively which should be more than 2 and
less than 10
8
0
5 9 7 6
8 0 1 2
7 7 4 8
5 6 7 9
0 1 8 2
7 7 4 8
ALGORITHM
STEP 1: Start of algorithm.
STEP 2: Input the no. of rows and columns and store it in respective integer
STEP 6: Create a loop from (i=0) and continue till (i<m), to keep the value of ‘i’
fixed
STEP 7: Now, to sort the matrix using the Bubble sort technique, create an outer
loop inside the previous loop starting from (j=0) and continue it till (j<n-1).
STEP 8: Create an inner loop starting from (k=0) and continue it till (k<n-1-i).
STEP 9: In the if block, check if the first element (a[i][k]) of the rows is greater than
the second element (a[i][k+1]) or not. If it is so, the elements are swapped using a
temporary variable ‘t’. This is done to sort the elements of each row in the
ascending
order.
STEP 10: Now, print the new matrix, i.e the resultant array, after sorting each row.
column is equal to the element of the jth row and ith column.
8.CODE
import java.util.Scanner;
class Symmetric
int a[][],i,j,m,flag=0;
m=sc.nextInt();
if((m>2)&&(m<10))
a=new int[m][m];
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
a[i][j]=sc.nextInt();
for(i=0;i<m;i++)
for(j=0;j<m;j++)
System.out.print(a[i][j]+"\t");
System.out.print("\n");
for(i=0;i<m;i++)
for(j=0;j<m;j++)
if(i!=j)
if(a[i][j]==a[j][i])
flag=1;
else
flag=0;
break;
if(flag==1)
else
else
System.out.println("Invalid input");
OUTPUT:
Enter the dimension of the square matrix which should be more than 2 and less
than 10
7
9
45
78
3 7 9
0 3 6
45 78 1
ALGORITHM
STEP 1: Start of algorithm.
STEP 2: Input the size of the square matrix and store it in an integer variable ‘m’.
STEP 3: In an if block, check for the range of ‘m’ which is greater then 2 and less
STEP 5: Print the original elements of the matrix, i.e the source array which was
STEP 7: Create another similar inner loop starting from (j=0) and continue it till
(j<m).
STEP 8: Next, create an outer if block and check whether the values of ‘i’ and ‘j’
equal or not, using a condition [ if(i!=j) ]. If the condition is not satisfied another
iteration of the loop takes place and this continues until this condition gets
satisfied.
previous condition of the outer if block is satisfied, the control enters this block to
check whether the element of the ith row and jth column (a[i][j]) is equal to the
element
STEP 10: If this condition is satisfied, the value of ‘flag’ is assigned to 1. If the
condition is not satisfied then the value of ‘flag’ is assigned to 0 using an else
block.
STEP 11: Now, check whether the value of ‘flag’ is equal to 1 or not, using an if
block
the square matrix is not Symmetric. Print a message saying (“The matrix is not
Symmetric”), using an else block.
STEP 12: Lastly, for an invalid input, print a message saying (“Invalid input”).
9.CODE
class BSum
int i,j,m,sb=0,snb=0;
matrix");
m=sc.nextInt();
int A[][]=new int[m][m];
for(i=0;i<m;i++)
for(j=0;j<m;j++)
A[i][j]=sc.nextInt();
System.out.print("Original Matrix");
for(i=0;i<m;i++)
for(j=0;j<m;j++)
System.out.print(A[i][j]+" ");
System.out.println();
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
if(i==0 ||i==m-1||j==0||j==m-1)
{ System.out.print(A[i][j]+" ");
sb=sb+A[i][j];
else
System.out.print(" ");
System.out.println();
for(i=0;i<m;i++)
for(j=0;j<m;j++)
{ System.out.print(A[i][j]+" ");
snb=snb+A[i][j];
}
else
System.out.print(" ");
System.out.println();
System.out.println("Boundary Sum"+sb);
OUTPUT:
Enter the row & column of thE matrix3
Original Matrix2 5 9
062
562
259
0 2
562
Boundary Sum31
Algorithim:-
StepI:- Start of Algorithm
columns.
non-boundary elements(snb ).
StepXI:-End of algorithm.
of the outerloop
of inner loop
boundary
elemnts
non-boundary
elements
10.CODE:
import java.util.*;
class CircularMA
int n;
n=sc.nextInt();
int r1=0,c1=0,r2=n-1,c2=n-1,i,j,r,c;
int a[][];
a=new int[n][n];
int k=1;
while(r1<=r2&&c1<=c2)
for(i=c1;i<=c2;i++)
a[r1][i]=k;
k++;
for(j=r1+1;j<=r2;j++)
a[j][c2]=k;
k++;
for(i=c2-1;i>=c1;i--)
a[r2][i]=k;
k++;
for(j=r2-1;j>=r1+1;j--)
a[j][c1]=k;
k++;
}
r1++;
r2--;
c1++;
c2--;
for(r=0;r<n;r++)
{for(c=0;c<n;c++)
System.out.print(a[r][c]+" ");
}System.out.println();
OUTPUT:
Enter the value of n4
1234
12 13 14 5
11 16 15 6
10 9 8 7
ALGORITHM:
Step 1 : Start of algotithm
10
step (b)
(b) Store the natural numbers in the first row using A[r1][i]
= k++
Step 7 : (a) Start a for loop from j = r1+1 to r2, where ‘j’
step (b)
(b) Store the natural numbers in the last column using
A[j][c2] = k++
Step 8 : (a) Start a for loop from i = c2-1 to c1, where ‘i’
step (b)
(b) Store the natural numbers in the last row using A[r2][i] =
k++
Step 9 : (a) Start a for loop from j = r2-1 to r1+1, where ‘j’
A[j][c1] = k++
first row
last row
last column
outer loop
inner loop
rows
column
11.ALGORITHM:
Step 1: Start of algorithm.
Step 5: If c! = ‘.’ AND c! = ‘!’ AND c! = ‘?’ then display “Sentence must be
terminated with ‘.’,
steps 7 to 9.
Step 8: Find the first (char c1) and last letter (char c2) of each extracted word.
Step 9: If ‘c1’ and ‘c2’ are both vowels, then add the word to String s2 and
increment ‘n’ by 1
Step 10: Display “ Number of words beginning and ending with vowel :”+n.
CODE:
import java.util.*;
class Vowel
String s,s1="",s2="",s3="";
int i,l,n=0;
char c,c1,c2;
System.out.println("Enter a sentence:");
c=s.charAt(l-1);
given condition
System.exit(0);
for(i=0;i<l;i++)
c=s.charAt(i);
else
n++;
else
s3=s3+s1+" ";
s1="";
return true;
else
return false;
OUTPUT:
Enter a sentence:
VARIABLE DESCRIPTION:
main() :
Name DataTypePurpose
s3 String For storing words not beginning and ending with vowel.
isVowel() :-
12.ALGORITHM:
Step 1: Start of algorithm.
Step 10: Start a for loop from i=0; i<l; i++ and repeat steps 11 and 12.
Step 14: if(c%2==0) then display “Evil number” else display “Not Evil number”.
Step 15: End of algorithm.
CODE:
import java.util.*;
class EvilNumber
int r;
while(n>0)
s=dig[r]+s; //adding the remainder to the result and reversing at the same
time
n=n/2;
return s;
}
int countOne(String s) // Function to count no of 1's in binary number
int c = 0, l = s.length();
char ch;
ch=s.charAt(i);
if(ch=='1')
c++;
return c;
int n = sc.nextInt();
int x = ob.countOne(bin);
if(x%2==0)
else
OUTPUT:
Enter a positive number : 5
Number of Ones = 2
5 is an Evil Number.
VARIABLE DESCRIPTION:
toBinary() :-
countOne() :-
main() :-
13.CODE:
import java.util.Scanner;
String s;
void input()
char c;
do
System.out.println("Enter a sentence");
s=sc.nextLine().toUpperCase();
c=s.charAt(s.length()-1);
break;
while(true);
void decode()
int ch=64,j=0;
ab[i]=(char)(++ch);
no[i]=++j;
s=s.substring(0,s.length()-1)+" ";
for(int i=0;i<s.length();i++)
if(s.charAt(i)!=' ')
w=w+s.charAt(i);
else
word[++c]=w;
sum=0;
for(int k=0;k<w.length();k++)
for(int m=0;m<26;m++)
if(w.charAt(k)==ab[m])
sum+=no[m];
value[c]=sum;
w="";
for(int q=0;q<=c-1;q++)
for(int r=0;r<c-q;r++)
if(value[r]>value[r+1])
int temp=value[r];
value[r]=value[r+1];
value[r+1]=temp;
String t=word[r];
word[r]=word[r+1];
word[r+1]=t;
}
}
for(int i=0;i<=c;i++)
System.out.print(word[i]+" ");
ob.input();
ob.decode();
OUTPUT:
Enter a sentence
Enter a sentence
STEP 2: Declare a method input() and takes a sentence as input until the sentence
STEP 4: Declare a char array’ ab’ and int array’ no’ each of size 26 to store the
alphabets and their encrypted values respectively.Then using a for loop initialize
the values.
STEP 5: Remove the special character and add a space at the end of the sentence.
Declare a String array’ word’ and int array’ value’ each of size ‘s.length’ to store
STEP 6: Using a for loop extract the words and store them in the array ‘word’.Use
a counter variable ‘c’ for determining the index numbers.Then calculate the
potential values of the words and store it temporarily in a variable named ‘sum’
and afterwards store it in array’ value’ at position ‘c’. Empty the ‘sum’ and the
STEP 7: Using bubble sort technique, sort the array ‘value’ in ascending order and
STEP 9: Declare a main method and create an object to call the methods input()
and decode_sort()
STEP 10: End of the algorithm.
value of alphabet
int c=0;
System.out.println("Enter size");
int n=sc.nextInt();
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
System.out.println("Enter a number");
a[i][j]=sc.nextInt();
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
System.out.print(a[i][j]+"\t");
System.out.println();
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(i!=j)
if(a[i][j]!=0)
++c;
if(c>0)
else
OUTPUT:
Enter size
Enter a number
Enter a number
Enter a number
Enter a number
Enter a number
Enter a number
Enter a number
Enter a number
0
Enter a number
1 0 0
0 2 0
0 0 0
It is a diagonal matrix
ALGORITHM:
STEP 1: Start of the algorithm
STEP 2: Input the size of the square matrix and store it in a integer variable ‘n’.
STEP 5: Initialize and declare the variables i=0 and j=0 and start a for loop from i=0
to less than n and gets incremented by 1 with each iteration.Start a for loop from
STEP 6: Take input from the user and fill the array a[i][j]=sc.nextInt()
STEP 8: Initialize and declare the variables i=0 and j=0 and start a for loop from
i=0 to less than n and gets incremented by 1 with each iteration.Start a for loop
from j=0 to less than n which gets incremented by 1 with each iteration.
Within the inner loop, check if(i!=j) and if it is true, then check if(a[i][j]!=0) and if
this condition is tue then increase the value of c.
STEP 9: If c>0, print “Not a Diagonal matrix” otherwise print “It is a diagonal
matrix”.
15.CODE:
class FrequencyCharacter
int i, j;
freq[i] = 1;
if(string[i] == string[j]) {
freq[i]++;
string[j] = '0';
}
OUTPUT:
Characters and their corresponding frequencies
p-2
i-1
c-2
t-2
u-1
r-2
e-3
f-1
ALOGORITHM
STEP 1: START
STEP 4: DEFINE i, j
li=""></str.length<>
li=""></str.length<>
STEP 9: IF (string[i] == string[j]) then
freq[i]++
string[j]= 0
li=""></freq.length<>
16.CODE:
import java.util.Scanner;
class primeMain
{
int n;
n= sc.nextInt();
if(obj.prime(n,2)==1)
System.out.println("prime number");
else
class primerecurse
if(y>=2)
{
if(y%i!=0)
return prime(y,++i);
else if(y==i)
return 1;
else
return 0;
else
return 0;
OUTPUT:
enter the number
11
prime number
ALOGIRTHM
STEP 1: start
STEP 2: creating an object which contains the function that checks whether a
number is prime or
not.
STEP 5: The function int prime() first checks whether the number is > or = to 2 or
not
17.CODE:
import java.util.Scanner;
class fiboMain
{
public static void main(String []args)
int n;
n=sc.nextInt();
for(int i=0;i<n;i++)
System.out.println(obj.fibo(i));
class fiborec
int fibo(int i)
if(i==0||i==1)
return i;
else
return(fibo(i-1)+fibo(i-2));
OUTPUT:
The first n numbers of the fibonacci series
ALGORITHM:
Step 1: Start of the algorithm.
Step 4: The recursive function int fibo() gets called by the object obj.fibo(i).
Step 5:Now the value of i gets checked and then it returns the corresponding value
to the for loop.
18.CODE:
import java.util.Scanner;
class gcdMain
int a,b;
a=sc.nextInt();
b=sc.nextInt();
System.out.println(obj.gcd(a,b));
}
class gcdrec
if(a==0)
return b;
else if(b==0)
return a;
else if(a==b)
return a;
else if(a>b)
return gcd(a-b,b);
else
return gcd(a,b-a);
OUTPUT:
enter the values
45
15
15
VARIABLE DECLARATION TABLE:
Name Data Type Purpose
ALGORITHM:
Step 1: Start of algorithm.
Step 3:The recursive function int gcd() is called through the object obj.gcd(a,b).
Step 4: Now the values of a and b are checked in the corresponding if and else if
statement.
Step 5: Then the return statement gets executed according to the conditional
statements.
19.CODE:
import java.util.Scanner;
class A19
{
if(l<0)
return;
else
System.out.println(s.charAt(l));
reverse(s,--l);
import java.util.Scanner;
class b
a obj=new a();
String s;
s=sc.nextLine();
int l=s.length();
obj.reverse(s,l-1);
}
OUTPUT:
geeks for geeks
ALGORITHM :
Step 1: Start the alg orithm.
Step 2: Use void reverse() function to accept a string variable and an integer
variable l for the length
of the string.
Step 3:Now check whether the length of the string is less than zero or not.
Step 6: Input a string in the main class and also find the length of the string.
20.CODE:
import java.util.Scanner;
class Bi
int m;
if(l<=u)
m=(l+u)/2;
if(s==a[m])
return m;
else if(s<a[m])
return binary_search(a,l,(m-1),s);
else if(s>a[m])
return binary_search(a,(m+1),u,s);
return -1;
import java.util.Scanner;
class Na
Bi obj=new Bi();
int arr[],n,i,lb,ub,d,r,j,temp;
n=sc.nextInt();
for(i=0;i<n;i++)
arr[i]=sc.nextInt();
d=sc.nextInt();
lb=0;ub=n-1;
for(i=0;i<n-1;i++)
for(j=0;j<n-1-i;j++)
if(arr[j]>arr[j+1])
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
r=obj.binary_search(arr,lb,ub,d);
if(r==-1)
OUTPUT:
Enter the number of elements in the array
67
09
10
10
Element present
ALGORITHM :
Step 1: Start the algorithm
Step 3: Now use an integer value m to find the middle most value from the
variables declared
in the array.
Step 4: Now compare the middle most value with the value to be searched.
Step 5: If the number to be searched is less than the middle most value then
perform the
Step 6: If the number to be searched is more than the middle most value then
perform the