0% found this document useful (0 votes)
22 views62 pages

Computer Practical File 2025-26

Computer project for class 10 icse

Uploaded by

ansi161279
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views62 pages

Computer Practical File 2025-26

Computer project for class 10 icse

Uploaded by

ansi161279
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Session: 2025-26

COMPUTER
PRACTICAL FILE
SUBMITTED TO: SUBMITTED BY:
Mr. Vijay Baretha

Class :

Roll No:

________________ ______________
External Examiner 1 Internal Examiner
ACKNOWLEDGEMENT
I would like to thank my Computer Application teacher
[Link] Baretha for his able guidance and support in
completing my project. I would also like to extend my
gratitude to the Principal Rev. Fr. Gerald D‟Souza for
providing me with all the facility that was required.

Date:

Name: ________________

Class:______________

2
INDEX
[Link]. Question Page Remarks
no.
WAP to input the names of 5 cities in an array
1 6
and search for names of the cities in an array
using linear search.

WAP to input an array of size 10 in ascending


2 order and search for a value using Binary search 8
technique.

3 WAP to print the following pattern 10


WAP to print the following pattern:
4 12

5 WAP to input the age, gender (and Taxable 14


Income of person male or female) and Taxable
Income of a person .If the age more than 65 years
or the gender is female, display “wrong category”.
If the age is less than or equal to 65 years and the
gender is male<compute and display the income
Tax payable as per the table give below

6 WAP to input three number and print them in 16


ascending order(using else-if ladder)

7 WAP to input three number and print them in 18


ascending order(using else-if ladder

8 WAP to take a number from the user and check 20


and print weather the given number is Spy number
or Not.

9 WAP to input a number and print whether it is a 22


HAPPY number or not.

3
[Link]. Question Page Remarks
no.

10 WAP to input a string and check whether a string 24


is starting with a vowel and ending with
Consonant or not.

11 WAP to input a string and remove duplicate 26


characters from the string.

12 WAP to print the following series:- 28

13 WAP to print the following series:- 30

14 WAP to overload a function named „alter‟ as 32


follows;
1).alter (int a): to take an int value and double it
then subtract 3 from it and then return the final
value.
2).alter (String s): to take a string value and return
it in reverse order.
3).alter (char c): to take a character value and
return the next alphabet.
Write a program to input a no and print the
15 frequency of each digit of a no. 35

Write a program to overload the function area () to


16 calculate the following as per the specifications 37
given below:
Member functions:
void area(int) : to calculate the area of square
void area(int, int) : to calculate the area of
rectangle using the formula length * breadth
void area(double ) : to calculate the area of circle

4
[Link]. Question Page Remarks
no.

17 Create a class prime palindrome with following 40


specifications.

18 WAP to define a function int fact (int n) used to 43


find factorial on n. Calculate value of S in main
function S= n!/(m!(n-m)!
WAP to input a word and check for palindrome
19 string. 45

WAP to input a string and print the following.


20 Sample input : SUNIL KUMAR SINGH 47
Sample output: [Link]

WAP to input a matrix of size 4x4 and print the


21 sum of boundary elements. 49

WAP to input a matrix of size 4x4 and print the


22 sum of diagonals elements of the matrix. 51

WAP to input a matrix of size 4x4 and print the


23 transpose of the matrix. 54

WAP to input an integer array of size 10 and sort


24 then in ascending order by using selection sort. 57

WAP to input an int array of size 10 and sort then


25 in descending order by using bubble sort. 60

5
PROGRAM-1
WAP to input the names of 5 cities in an array and search for names
of the cities in an array using linear search.

import [Link].*;
class city
{
public static void main(String args[])
{
String a[ ]=new String [5];
int f=0,i,x;
Scanner sc= new Scanner([Link]);
[Link]("Enter the names of 5 cities");
for(i=0;i<5;i++)
{
a[i]=[Link]();
}
[Link]("Enter the city name to be search");
String s=[Link]();
for(x=0;x<=4;x++)
{
if(a[x].equals(s))
{
f=1;
break;
}
}
if(f==1)
[Link]("City name found at position="+(x+1));
else
[Link]("no such city name is found");
}
}

6
Output:

Variable description table

Name Type Purpose


a string Used to declare an
array of size 10.
i int Control Variable used
in for loop to input the
names of cities.
s String Used to store the
word to be search.
x int Control variable used
in the for loop to
search the names of
cities .

7
PROGRAM-2

WAP to input an array of size 5 in ascending order and search for a


value using Binary search technique.

import [Link].*;
class binary_search
{
public static void main( )
{
int a[ ]=new int[5];
int f=0,i,s,l,u,mid;
Scanner sc= new Scanner([Link]);
[Link]("Enter the vlaues in ascending order");
for(i=0;i<5;i++)
{
a[i]=[Link]();
}
[Link]("Enter the elementto be search");
s=[Link]();
l=0;
u=4;
while(l<=u)
{
mid=(l+u)/2;
if(a[mid]==s)
{
f=1;
[Link]("Element found at position="+(mid+1));
break;
}
else if(a[mid]<s)
l=mid+1;
else if(a[mid]>s)
u=mid-1;
8
}
if(l>u)
[Link]("No such Element name is found");
}
}

Output :

Variable description table

Name Type Purpose


a int To store value in an
array.
i int To use as a counter in
the for loop.
l int To store the lower limit.

u int To store the upper limit.


mid int To store middle index
S int To store searching value

9
PROGRAM-3

WAP to print the following pattern –


1
23
456
7 8 9 10
11 12 13 14 15

class nested_loop
{
public static void main()
{
int i,j,a=1;
for(i=1;i<=5;i++ )
{
for(j=1;j<=i;j++)
{
[Link](a+" ");
a++;
}
[Link]( );
}
}
}

10
Output:

Variable description table

Name Type Purpose


i int To use as a control variable in
for loop anto print the following
pattern.
j int To use as a control variable in
for loop anto print the following
pattern.
a int Use to print the value

11
PROGRAM-4

Wap to print the following pattern:


A
AB
ABC
ABCD
ABCDE
class nested_loop_13
{
public static void main()
{
int x=10,k;
char i,j;
for(i='A' ;i <='E';i++)
{
for(k=1;k<=x;k++)
{
[Link](" ");
}
x--;
for(j='A';j<=i;j++)
{
[Link](j);
}
[Link]( );
}
}
}

12
Output:

Variable description table

Name Type Purpose


i int To use as a control variable in
for loop to print the following
pattern.
j int To use as a control variable in
for loop to print the following
pattern.
k Int To use as a control variable in
for loop to print the following
pattern.

13
PROGRAM-5

WAP to input the age, gender (and Taxable Income of person male
or female) and Taxable Income of a [Link] the age more than 65
years or the gender is female, display “wrong category”. If the age is
less than or equal to 65 years and the gender is male<compute and
display the income Tax payable as per the table give below:

Taxable Income(TI)in Rs. Income Tax(IT) in Rs.


Does not exceed 160000 Nil
Is greater than Rs.160000 and less (TI-160000) *10%
than or equals to Rs.500000
Is greater than Rs. 500000 and less (TI-500000)*20%+34000
than or equals to Rs. 800000
Is greater than Rs. 800000 (TI-800000)*30%+94000

import [Link].*;
class Tax
{
public static void main()
{
Scanner sc= new Scanner([Link]);
double IT=0,TI;
int age;
char gender;
[Link]("Enter age ");
age=[Link]();
[Link]("Enter gender as m or f");
gender=[Link]().charAt(0);
[Link]("Enter total income of the person");
TI=[Link]();
if(age<=65 && gender=='m')
{
if(TI<=160000)
IT=0;
else if(TI>160000 && TI<=500000)
14
IT=(TI-160000)*0.1;
else if(TI>500000 && TI<=800000)
IT=((TI-500000)*0.2)+34000;
else if(TI>800000)
IT=((TI-800000)*0.3)+94000;
[Link]("INCOME TAX="+IT);
}
else
[Link]("Wrong category");
}
}
Output :

Variable description table

Name Type Purpose


age int To input age by the
user.
gender int To input gender by the
user.
TI int To input total income
by the user.
IT int To calculate total
income tax.

15
PROGRAM-6
WAP to input three number and print them in ascending order
(using else-if ladder)

import [Link].*;
class abc
{
public static void main()
{ Scanner sc= new Scanner([Link]);
int a,b,c;
[Link]("Enter the three values");
a=[Link]();
b=[Link]();
c=[Link]();
if(a>b && a>c)
{ if(b>c)
[Link](c+","+b+","+a);
else
[Link](a+","+c+","+a);
}
else if(b>a && b>c)
{
if(a>c)
[Link](c+","+a+","+b);
else
[Link](a+","+c+","+b);
}
else if(c>a && c>b)
{
if(a>b)
[Link](b+","+a+","+c);
else
[Link](a+","+b+","+c);
}
}
}

16
Output:

Variable description table

Name Type Purpose


a Int To input the value
from the user.
b Int To input the value
from the user.
c Int To input the value
from the user.

17
PROGRAM-7

WAP in Java to input a number and check whether it is a Duck


Number or not.

import [Link].*;
public class duck_number
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
int r,c=0,n;
[Link]("Enter your number to be checked.");
n=[Link]();
while(n!=0)
{
r=n%10;
n=n/10;
if(r==0)
c++;
}
if(c>0)
[Link]("It is a duck number.");
else
[Link]("It is not a duck number.");
}
}

18
Output:

Variable description tabl


Name Type Purpose
n int To take input of user
r int To store the extract
digit
c int As a counter for how
many times a
condition is met.

19
PROGRAM-8
WAP to take a number from the user and check and print weather
the given number is Spy number or Not.

import [Link].*;
class spy_num
{
public static void main( )
{
Scanner sc= new Scanner([Link]);
int r,S=0,p=1,n;
[Link]("Enter the value");
n=[Link]();
while(n!=0)
{
r=n%10;
n=n/10;
S=S+r;
p=p*r;
}
if(S==p)
[Link]("Spy Number.");
else
[Link]("Not a Spy Number.");
}
}

20
Output:

Variable description table


Name Type Purpose
s int To find the sum of the
digits.
P int To find the product of
the digits.
r int To remove the digits
from the inputed
number.
n int To input the number
from the user.

21
PROGARM-9
WAP to input a number and print whether it is a HAPPY numberor not.
import [Link].*;
class Happy
{
public static void main(String args[])
{
int num;
Scanner sc=new Scanner([Link]);
[Link]("Enter a positive integer");
num=[Link]();
int dig,sum=0,m=num;
while(num>9)
{
while(num>0)
{
dig=num%10;
sum=sum+(dig*dig);
num=num/10;
}
num=sum;
sum=0;
}
if(num==1)
{
[Link](m+"is a HAPPY number");
}
else
{
22
[Link](m+"is not a HAPPY number");
}}}
Output :

Variable description table

Name Type Purpose


num int Stores the number to
be entered by the user.
dig int Stores the digits of the
number.
sum int Finds the sum of the
squares of the
numbers.

23
PROGRAM-10

WAP to input a string and check whether a string is starting with a


vowel and ending with consonant or not.
import [Link].*;
class abc
{
public static void main()
{
Scanner sc = new Scanner([Link]);
int l;
char ch,ch1;
[Link]("enter the stirng ");
String s= [Link]();
String s1="AEIOUaeiou";
l=[Link]();
ch=[Link](0);
ch1=[Link](l-1);
if([Link](ch)>=0 && [Link](ch1)==-1)
[Link]("String starting with vowel and ending with
consonant.");
else
[Link]("NOT starting with vowel and ending with
consonant.");
}
}

24
Output :

Variable description table


Name Type Purpose
s string To store the string
inputted by the user.
s1 string To store the vowels of
both cases.
l int To find the length of
the string s.
ch char To find whether the
string starts with a
vowel or not.
ch1 char To find whether the
string ends with a
consonant or not.

25
PROGRAM-11

WAP to input a string and remove duplicate characters from the


string.

import [Link].*;
class abc
{
public static void main()
{
Scanner sc = new Scanner([Link]);
int i,l;
char ch;
String s,s2="";
[Link]("Enter the string");
s=[Link]();
l= [Link]();
for(i=0;i<=l-1;i++)
{
ch=[Link](i);
if([Link](ch)==-1)
s2=s2+ch;
}
[Link](s2);
}
}

26
Output:

Variable description table

Name Type Purpose


i int To use as a counter in
the for loop.
l int To find the length of
the string.
s string To input the string
from the user.
ch char To find out the
duplicate of the
character.

27
PROGRAM-12

WAP to print the following series:-


S=x1/1! + x2/2! + x3/3!.............. n terms.

import [Link].*;
class series
{
public static void main( )
{
Scanner sc= new Scanner([Link]);
int i,d,s=0,f=1,x,n;
[Link]("enter the value of the x and N");
x=[Link]();
n=[Link]();
for(i=1;i<=n;i++)
{
f=f*i;
d=(int) [Link](x,i)/f;
s=s+d;
}
[Link]("The sum of the series is="+s);
}
}

28
Output:

Variable description table

Name Type Purpose


x int To input the value
from the user.
n int To input the value
from the user.
i int To use as a counter in
the for loop.
d int To find the value
according to the series.
s int To add all values.

f int To use as a variable in


the dividing part of the
string.

29
PROGRAM-13

WAP to print the following series:-


1,4,5,10,19…………………..n terms.

import [Link].*;
class abc
{
public static void main()
{
Scanner sc= new Scanner([Link]);
int i,a=1,b=4,c=5,d,n;
[Link]("Enter the limit");
n=[Link]();
[Link](a+","+b+","+c);
for(i=1;i<=n-3;i++)
{
d=a+b+c;
[Link](","+d);
a=b;
b=c;
c=d;
}
}
}

30
Output :

Variable description table


Name Type Purpose
n int To input the number of
iteration inputted by
the user.
i int To use as a counter in
the for loop.
a int Inputting the value 1.
b int Inputting the value 4.
c int Inputting the value 5.
d int To add all the values
and print them.

31
PROGRAM-14

WAP to overload a fuction named „alter‟ as follows;


1)int alter(int a): to take an int value and double it then subtract 3
from it and then return the final value.
2)String alter(String s):to take a string value and return it in reverse
order.
3)char alter(char c):to take a character value and return the next
alphabet.

import [Link].*;
class funcDak
{
public int alter(int a)
{
int b=a*2-3;
return b;
}
public String alter(String s)
{
int len=[Link]();
String n="";
for(int x=0;x<len;x++)
{
char c=[Link](x);
n=c+n;
}
return n;
}

32
public char alter(char c)
{
char m=(char)(c+1);
return m;
}
public static void main()
{
funcDak ob= new funcDak();
int x=[Link](7);
[Link]("The result of the first function is="+x);
String s=[Link]("apple");
[Link]("The result of the second function is="+s);
}
}

33
Output:

Variable Description table

Name Type Purpose

b int To change the value of


a into desired value.
len int To store length of
string s.
x int To use a counter
variable in the for
loop.
n string To store reverse value
of string s.
c char To extract the value of
string s.
m char To store altered value
of c.

34
PROGRAM-15

Write a program to input a no and print the frequency of each digit of


a no.

import [Link].*;
class while_loop_12
{
public static void main()
{
int r,c,i,m,n;
Scanner sc= new Scanner([Link]);
[Link]("Enter the number");
n=[Link]();
[Link]("Digit\tFrequency");
for(i=0;i<=9;i++)
{
m=n;c=0;
while(m!=0)
{
r=m%10;
m=m/10;
if(r==i)
c++;
}
if(c>0)
[Link](i+"\t"+c);
}
}
}

35
Output :

Variable Description table

Name Type Purpose

n int To store the numbert


i int Loop index variable

c int Counter variable to


count digit
r int To store the digit

36
PROGRAM-16

Write a program to overload the function area () to calculate the


following as per the specifications given below:
Member functions:
void area(int) : to calculate the area of square
void area(int, int) : to calculate the area of rectangle using the formula
length * breadth
void area(double ) : to calculate the area of circle
import [Link].*;
class abc
{
public void area(int a)
{
int s;
s=a*a;
[Link]("the area of square is="+s);
}
public void area(int l, int b)
{
int ar;
ar=l*b;
[Link]("the area of rectangle is="+ar);
}
public void area (double r)
{
double ar;
ar=3.14*r*r;
[Link]("the area of circle is="+ar);
}
public static void main()
37
{
abc ob= new abc();
Scanner sc= new Scanner([Link]);
int ch;
[Link]("Enter 1. for area of square\n2. for area of rectangle\n3.
for area of circle");
ch=[Link]();
switch(ch)
{
case 1:
[Link]("enter the side of square");
int s=[Link]();
[Link](s);
break;
case 2:
[Link]("enter the lenght and breadth");
int l=[Link]();
int b=[Link]();
[Link](l,b);
break;
case 3:
[Link]("enter the radius");
double r=[Link]();
[Link](r);
break;
default :
[Link]("invalid choice");
}
}
}

38
Output :

Variable description table


Name Type Purpose
ch int To store the user
choice
l int To store the length

b int To store the width

r double To store the radius

s int To store the side of


square.

39
PROGRAM-17

Create a class prime palindrome witn following specifications

 class name Primepalindrome.


 member functions.
 boolean isprime(int n) return.
 true if number is prime else return false.
 boolean ispalindrome(int n) return true if n is palindrome else
return false.
 void display(int n1, int n2).
 print all the prime palindrome number between n1 and n2.
 write a main method to create object of a clss and call the above
methods.

import [Link].*;
class Prime_palindrom
{
public boolean is_prime (int x)
{
int i, c=0;
for(i=1;i<=x;i++)
{
if(x%i==0)
c++;
}
if(c==2)
return true;
else
return false;
}
public boolean is_palin(int x)
{
int s=0,r,m=x;
while(x!=0)
40
{
r=x%10;
x=x/10;
s=10*s+r;
}
if(s==m)
return true;
else
return false;
}
public void show(int n1, int n2 )
{
int i;
boolean Z, K;
for(i=n1;i<=n2;i++)
{
Z=is_prime(i);
K=is_palin(i);
if(Z==true && K==true)
[Link](i+",");
}
}
public static void main ()
{
Scanner sc= new Scanner([Link]);
Prime_palindrom ob =new Prime_palindrom( );
int a,b;
[Link]("enter the lower limit");
a=[Link]();
[Link]("enter the upper limit");
b=[Link]();
[Link](a,b);
}
}

41
Output:

Variable description table

Name Type Purpose


n int To store the value
returned from the
main block.
i int To use as a control in
the for loop.
c int To count the number
of factors till the limit.
r int To Extract the digit
from the number
given by the user.
s int To store reverse of the
number inputted by
the user.
m int As a duplicate of the
number given by the
user
n1 int To store the value
returned from the
main block.
n2 int To store the value
returned from the
main block.
42
PROGRAM-18

WAP to define a function int fact(int n) used to find factorial on n.


calculate value of S in main function S= n!/(m!(n-m)!

import [Link].*;
class function_2
{
public int fact(int a)
{
int i,f=1;
for(i=1;i<=a;i++)
{
f=f*i;
}
return f;
}
public static void main( )
{
Scanner sc= new Scanner([Link]);
int x,y,z,n,m;
double s;
function_2 ob= new function_2();
[Link]("enter the value of n and m");
n=[Link]();
m=[Link]();
x=[Link](n);
y=[Link](m);
z=[Link](n-m);
s=1.0*x/(y*z);
[Link]("the value is ="+s);
}
}

43
Output:

Variable description table

Name Type Purpose


n int To store the value
coming from main
block.
i int To use as a counter in
the for loop.
f int To calculate value and
return it in the main
block.
n int To input the value
from the user.
m int To input the value
from the user.

44
PROGRAM-19

WAP to input a word and check for palindrome string.


import [Link].*;
class palindrome
{
public static void main()
{
Scanner sc = new Scanner( [Link]);
String s,s1="";
int i,l;
char ch;
[Link]("Enter the String");
s=[Link]();
l=[Link]();
for(i=0;i<=l-1;i++)
{
ch=[Link](i);
s1=ch+s1;
}
if([Link](s))
[Link]("Palindrome String");
else
[Link]("Not a Palindrome String");
}
}

45
Output:

Variable description table

Name Type Purpose


s String To store the stirng
value
s1 String To store the reverse

ch char To store the character


of the string.
i int Loop index variable

46
PROGRAM-20

WAP to input a string and print the following.


Sample input : SUNIL KUMAR SINGH
Sample output: [Link]
import [Link].*;
class ABC
{
public static void main()
{
Scanner sc = new Scanner( [Link]);
String s,s1="",s2="";
int i,l;
char ch;
[Link]("Enter the String");
s=[Link]();
l=[Link]();
for(i=0;i<=l-1;i++)
{
ch=[Link](i);
if(ch!=' ')
s1=s1+ch;
else
{
ch=[Link](0);
s2=s2+ch+".";
s1="";
}
}
[Link]("The result is="+s2+s1);
}
}

47
Output :

Variable description table

Name Type Purpose


s String To store the stirng
value
s1 String To store the word

ch char To store the character


of the string.
i int Loop index variable
s2 String To store the result
l int To store length of
string.

48
PROGRAM-21

WAP to input a matrix of size 4x4 and print the sum of boundary
elements.

import [Link].*;
class matrix_1
{
public static void main()
{
int i,j,s=0;
int a[][]=new int[4][4];
Scanner sc= new Scanner([Link]);
[Link]("enter the matrix ");
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
a[i][j]=[Link]();
}
}
[Link]("The original matrix is: ");
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
[Link](a[i][j]+" ");
}
[Link]();
}
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
if(i==0 || i==3 || j==0 || j==3)
s=s+a[i][j];
}
49
}
[Link]("the sum of boundary elements="+s);
}
}
Output :

Variable description table

Name Type Purpose


a int To store the matrix

s int To store the sum

i int Loop index variable


j int Loop index variable
50
PROGRAM-22

WAP to input a matrix of size 4x4 and print the sum of diagonals
elements of the matrix.

import [Link].*;
class matrix_3
{
public static void main()
{
int i,j,s=0,s1=0;
int a[][]=new int[4][4];
Scanner sc= new Scanner([Link]);
[Link]("enter the matrix ");
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
a[i][j]=[Link]();
}
}

for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
if(i==j)
s=s+a[i][j];
else if(i+j==3)
s1=s1+a[i][j];
}
}
[Link]("\nthe matrix elements is");
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
51
[Link](a[i][j]+" ");
}
[Link]();
}

[Link]("the sum of primary diagonal elements="+s);


[Link]("the sum of secondary diagonal elements="+s1);
}
}

Output :

52
Variable description table

Name Type Purpose


a int To store the matrix

s int To store the sum

i int Loop index variable


j int Loop index variable
s1 int To store the sum

53
PROGRAM-23

WAP to input a matrix of size 4x4 and print the transpose of the
matrix.

import [Link].*;
class matrix_6
{
public static void main()
{
int i,j;
int a[][]=new int[4][4];
int b[][]=new int[4][4];
Scanner sc= new Scanner([Link]);
[Link]("enter the matrix ");
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
a[i][j]=[Link]();
}
}
[Link]("\nThe original matrix elements is");
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
[Link](a[i][j]+" ");
}
[Link]();
}
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
b[j][i]=a[i][j];
}
54
}
[Link]("\nthe transopse matrix elements is");
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
[Link](b[i][j]+" ");
}
[Link]();
}
}
}

Output :

55
Variable description table

Name Type Purpose


a int To store the matrix

b int To store the transpose


matrix
i int Loop index variable
j int Loop index variable

56
PROGRAM-24

WAP to input an integer array of size 10 and sort then in ascending


order by using selection sort.

import [Link].*;
class selection_sort
{
public static void main()
{
Scanner sc= new Scanner([Link]);
int a[]= new int[10];
int i,p,min,j,t;
[Link]("enter the array element");
for(i=0;i<=9;i++)
{
a[i]=[Link]();
}
[Link]("\nThe original array is:");
for(i=0;i<=9;i++)
{
[Link](a[i]+",");
}
for(i=0;i<=9;i++)
{
p=i;
min=a[i];
for(j=i+1;j<=9;j++)
{
if(a[j]<min)
{
min=a[j];
p=j;
}
}
t=a[i];
a[i]=a[p];
57
a[p]=t;
}
[Link]("\nThe sorted array is:");
for(i=0;i<=9;i++)
{
[Link](a[i]+",");
}
}
}

Output :

58
Variable description table

Name Type Purpose


a int To store the array element

p int To store position of min


value
i int Loop index variable
j int Loop index variable
min int To store the min value

59
PROGRAM-25

WAP to input an int array of size 10 and sort then in descending order
by using bubble sort.

import [Link].*;
class bubble_sort
{
public static void main()
{
Scanner sc= new Scanner([Link]);
int a[]= new int[10];
int i,p,min,j,t;
[Link]("enter the array element");
for(i=0;i<=9;i++)
{
a[i]=[Link]();
}
[Link]("\nThe original array is:");
for(i=0;i<=9;i++)
{
[Link](a[i]+",");
}
for(i=0;i<=9;i++)
{

for(j=0;j<=8-i;j++)
{
if(a[j]<a[j+1])
{ t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}

}
[Link]("\nThe sorted array is:");
60
for(i=0;i<=9;i++)
{
[Link](a[i]+",");
}
}
}

Output :

61
Variable description table

Name Type Purpose


a int To store the array element

i int Loop index variable


j int Loop index variable

62

You might also like