0% found this document useful (0 votes)
3 views63 pages

Ojas Computer Project Class X

This document is a Computer Practical File submitted by Ojas Saxena for Class X-B, containing various programming assignments. It includes tasks such as searching arrays, printing patterns, and checking properties of numbers and strings, along with Java code implementations. The file also features an index and variable description tables for each program.

Uploaded by

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

Ojas Computer Project Class X

This document is a Computer Practical File submitted by Ojas Saxena for Class X-B, containing various programming assignments. It includes tasks such as searching arrays, printing patterns, and checking properties of numbers and strings, along with Java code implementations. The file also features an index and variable description tables for each program.

Uploaded by

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

Session: 2025-26

COMPUTER
PRACTICAL FILE
SUBMITTED TO: SUBMITTED BY:
Ms. Jaya Meghwani Ojas Saxena

Class: X – ‘B’

Roll No: 29

________________ ______________
External Examiner 1 Internal Examiner
ACKNOWLEDGEMENT
This I would like to thank my Computer Application
teacher Ms. Jaya Meghwani for her 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: Ojas Saxena

Class: X – ‘B’

2
INDEX
[Link]. Question Page Remarks
no.
WAP to input the names of 5 cities in an array 6
1
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

[Link]. Question Page Remarks


no.
4
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_search
{
public static void main(String args[])
{
String b[ ]=new String [5];
int g=0,j,y;
Scanner sc= new Scanner([Link]);
[Link]("Enter the name of any 5 cities");
for(j=0;j<5;j++)
{
b[j]=[Link]();
}
[Link]("Type the name of the city to be found");
String t=[Link]();
for(y=0;y<=4;y++)
{
if(b[y].equals(t))
{
g=1;
break;
}
}
if(g==1)
[Link]("Position of the city found is= "+(y+1));
else
[Link]("There is no such city");
}
}

6
Output:

Variable description table

Name Type Purpose


b string Used to declare an
array of size 10.
j int Control Variable used
in for loop to input the
names of cities.
t String Used to store the
word to be search.
y 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
{
public static void main( )
{
int b[ ]=new int[5];
int g=0,j,t,m,v,mid;
Scanner sc= new Scanner([Link]);
[Link]("Enter the vlaues in ascending order");
for(j=0;j<5;j++)
{
b[j]=[Link]();
}
[Link]("Enter the elementto be search");
t=[Link]();
m=0;
v=4;
while(m<=v)
{
mid=(m+v)/2;
if(b[mid]==t)
{
g=1;
[Link]("Element found at position="+(mid+1));
break;
}
else if(b[mid]<t)
m
=mid+1;
else if(b[mid]>t)
8
v=mid-1;
}
if(m>v)
[Link]("No such Element name is found");
}
}

Output :

Variable description table

Name Type Purpose


b int To store value in an
array.
j int To use as a counter in
the for loop.
m int To store the lower limit.

v int To store the upper limit.


mid int To store middle index
t 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 an to print the
following
pattern.
j int To use as a control variable in
for loop an to print the
following
pattern.
n int Use to print the value

11
PROGRAM-4

Wap to print the following pattern:


A
AB
ABC
ABCD
ABCDE

class pattern2
{
public static void main()
{
int n=10,a;
char i,j;
for(i='A' ;i <='E';i++)
{
for(a=1;a<=n;a++)
{
[Link](" ");
}
n--;
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.
a 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 taxonincome
{
public static void main()
{
Scanner sc= new Scanner([Link]);
double ictx=0,txin;
int age;
char gender;
[Link]("Enter the age ");
age=[Link]();
[Link]("Enter gender as male or female");
gender=[Link]().charAt(0);
[Link]("Enter the income of the person");
txin=[Link]();
if(age<=65 && gender=='m')
{
if(txin<=160000)
ictx=0;
else if(txin>160000 && txin<=500000)
14
ictx=(txin-160000)*0.1;
else if(txin>500000 && txin<=800000)
ictx=((txin-500000)*0.2)+34000;
else if(txin>800000)
ictx=((txin-800000)*0.3)+94000;
[Link]("Income Tax ="+ictx);
}
else
[Link]("Wrong criteria");
}
}

Output :

Variable description table

Name Type Purpose


age int To input age by the
user.
gender int To input gender by
the user.
txin int To input total income
by the user.
ictx 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 asc_order
{
public static void main()
{ Scanner sc= new Scanner([Link]);
int x,y,z;
[Link]("Enter three Distinct values");
x=[Link]();
y=[Link]();
z=[Link]();
if(x>y && x>z)
{ if(y>z)
[Link](z+","+y+","+x);
else
[Link](x+","+z+","+x);
}
else if(y>x && y>z)
{
if(x>z)
[Link](z+","+x+","+y);
else
[Link](x+","+z+","+y);
}
else if(z>x && z>y)
{
if(x>y)
[Link](y+","+x+","+z);
else
[Link](x+","+y+","+z);
}
}
16
Output:

Variable description table

Name Type Purpose


x Int To input the value
from the user.
y Int To input the value
from the user.
z 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 s,d=0,num;
[Link]("Enter your number to be checked.");
num=[Link]();
while(num!=0)
{
s=num%10;
num=num/10;
if(s==0)
d++;
}
if(d>0)
[Link]("The value given is a Duck Number.");
else
[Link]("The value given is not a Duck Number.");
}
}

Name Type Purpose


18
num int To take input of user
s int To store the extract
digit
d int As a counter for how
many times a
condition is met.

Output:

Variable description table

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 spynumber
{
public static void main( )
{
Scanner sc= new Scanner([Link]);
int s,t=0,q=1,num;
[Link]("Enter the value");
num=[Link]();
while(num!=0)
{
s=num%10;
num=num/10;
t=t+s;
q=q*s;
}
if(t==q)
[Link]("Spy Number.");
else
[Link]("Not a Spy Number.");
}
}

20
Output:

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.

Variable description table

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

Variable description table


Name Type Purpose
n int Stores the number to
be entered by the user.
d int Stores the digits of the
number.
s 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 vowel
{
public static void main()
{
Scanner sc = new Scanner([Link]);
int m;
char c1,c2;
[Link]("Enter the string.");
String s= [Link]();
String s1="aeiouAEIOU";
m=[Link]();
c1=[Link](0);
c2=[Link](m-1);
if([Link](c1)>=0 && [Link](c2)==-1)
[Link]("Starting with vowel and ending with consonant.");
else
[Link]("NOT Starting with vowel and NOT ending with
consonant.");
}
}

Output :
24
Name Type Purpose
s string To store the string
inputted by the user.
s1 string To store the vowels of
both cases.
m int To find the length of
the string s.
c1 char To find whether the
string starts with a
vowel or not.
c2 char To find whether the
string ends with a
consonant or not.
Variable description table

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 j,m;
char ch;
String st1,st2="";
[Link]("Enter the string: ");
st1=[Link]();
m= [Link]();
for(j=0;j<=m-1;j++)
{
ch=[Link](j);
if([Link](ch)==-1)
st2=st2+ch;
}
[Link](st2);
}
}

26
Output:

Name Type Purpose


j int To use as a counter in
the for loop.
m int To find the length of
the string.
st1 string To input the string
from the user.
ch char To find out the
duplicate of the
character.
Variable description table

27
PROGRAM-12

WAP to print the following series:-


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

import [Link].*;
class num_series
{
public static void main( )
{
Scanner sc= new Scanner([Link]);
int j,e,u=0,g=1,y,o;
[Link]("Enter the values of X and N: ");
y=[Link]();
o=[Link]();
for(j=1;j<=o;j++)
{
g=g*j;
e=(int) [Link](y,j)/g;
u=u+e;
}
[Link]("Sum of the series is: "+u);
}
}

28
Output:

Variable description table

Name Type Purpose


y 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 :

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.
Variable description table

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;
}
public char alter(char c)
{
char m=(char)(c+1);
32
return m;
}
public static void main()
{
funcDak ob= new funcDak();
int x=[Link](8);
[Link]("First function's result is = "+x);
String s=[Link]("banana");
[Link]("Second function's result is = "+s);
}
}

Output:

33
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 whileloop12
{
public static void main()
{
int s,d,j,n,o;
Scanner sc= new Scanner([Link]);
[Link]("Enter the digit");
o=[Link]();
[Link]("Digit \t Frequency");
for(j=0;j<=9;j++)
{
n=o;d=0;
while(n!=0)
{
s=n%10;
n=n/10;
if(s==j)
d++;
}
if(d>0)
[Link](j+"\t"+d);
}
}
}

35
Output :

Variable Description table

Name Type Purpose

o int To store the number t


j int Loop index variable

d int Counter variable to


count digit
S 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 Prime_palindrome.


 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_palindrome
{
public boolean isprime (int y)
{
int j, d=0;
for(j=1;j<=y;j++)
{
if(y%j==0)
d++;
}
if(d==2)
return true;
else
return false;
}
public boolean ispalin(int x)
{
int t=0,s,n=x;
while(x!=0)
40
{
s=x%10;
x=x/10;
t=10*t+s;
}
if(t==n)
return true;
else
return false;
}
public void show(int m1, int m2 )
{
int i;
boolean h, l;
for(i=m1;i<=m2;i++)
{
h=isprime(i);
l=ispalin(i);
if(h==true && l==true)
[Link](i+",");
}
}
public static void main ()
{
Scanner sc= new Scanner([Link]);
Prime_palindrome ob =new Prime_palindrome( );
int c,d;
[Link]("Enter the lower limit: ");
c=[Link]();
[Link]("Enter the upper limit: ");
d=[Link]();
[Link](c,d);
}
}

41
Output:

42
Variable description table

Name Type Purpose


o int To store the value
returned from the
main block.
j int To use as a control in
the for loop.
d int To count the number
of factors till the
limit.
s int To Extract the digit
from the number
given by the user.
t int To store reverse of
the number
inputted by
the user.
n int As a duplicate of the
number given by the
user
m1 int To store the value
returned from the
main block.
m2 int To store the value
returned from the
main block.

43
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 function1
{
public int fact(int b)
{
int j,g=1;
for(j=1;j<=b;j++)
{
g=g*j;
}
return g;
}
public static void main( )
{
Scanner sc= new Scanner([Link]);
int w,x,y,o,n;
double t;
function1 ob= new function1();
[Link]("Enter the value of o and n: ");
o=[Link]();
n=[Link]();
w=[Link](o);
x=[Link](n);
y=[Link](o-n);
t=1.0*w/(x*y);
[Link]("The value is: "+t);
}
}

Output:

44
Variable description table
Name Type Purpose
o int To store the value
coming from main
block.
j int To use as a counter in
the for loop.
g int To calculate value and
return it in the main
block.
o int To input the value
from the user.
n int To input the value
from the user.

45
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 s1,s2="";
int j,m;
char ch;
[Link]("Enter the String");
s1=[Link]();
m=[Link]();
for(j=0;j<=m-1;j++)
{
ch=[Link](j);
s2=ch+s2;
}
if([Link](s1))
[Link]("The string entered is Palindrome.");
else
[Link]("The string entered is NOT Palindrome.");
}
}

46
Output:

Variable description table

Name Type Purpose


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

ch char To store the character


of the string.
i int Loop index variable

47
PROGRAM-20

WAP to input a string and print the following.


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

48
Output :

Variable description table

Name Type Purpose


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

ch char To store the character


of the string.
j int Loop index variable
s3 String To store the result
m int To store length of
string.

49
PROGRAM-21

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

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

Output :

51
Variable description table

Name Type Purpose


a int To store the matrix

t int To store the sum

j int Loop index variable


k int Loop index variable

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

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

for(j=0;j<=3;j++)
{
for(k=0;k<=3;k++)
{
if(j==k)
s1=s1+a[j][k];
else if(j+k==3)
s2=s2+a[j][k];
}
}
[Link]("\nthe matrix elements is: ");
for(j=0;j<=3;j++)
{
for(k=0;k<=3;k++)
{
[Link](a[j][k]+" ");
53
}
[Link]();
}
[Link]("The sum of primary diagonal elements: "+s1);
[Link]("The sum of secondary diagonal elements: "+s2);
}
}

Output :

54
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

55
PROGRAM-23

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

import [Link].*;
class matrix3
{
public static void main()
{
int j,k;
int a[][]=new int[4][4];
int b[][]=new int[4][4];
Scanner sc= new Scanner([Link]);
[Link]("Enter the matrix: ");
for(j=0;j<=3;j++)
{
for(k=0;k<=3;k++)
{
a[j][k]=[Link]();
}
}
[Link]("\nThe original matrix elements is: ");
for(j=0;j<=3;j++)
{
for(k=0;k<=3;k++)
{
[Link](a[j][k]+" ");
}
[Link]();
}
for(j=0;j<=3;j++)
{
for(k=0;k<=3;k++)
{
b[k][j]=a[j][k];
}
56
}
[Link]("\nThe transopse matrix elements is: ");
for(j=0;j<=3;j++)
{
for(k=0;k<=3;k++)
{
[Link](b[j][k]+" ");
}
[Link]();
}
}
}
Output :

57
Variable description table

Name Type Purpose


b int To store the matrix

c int To store the transpose


matrix
j int Loop index variable
k int Loop index variable

PROGRAM-24
58
WAP to input an integer array of size 10 and sort then in ascending
order by using selection sort.

import [Link].*;
class selectionsort
{
public static void main()
{
Scanner sc= new Scanner([Link]);
int a[]= new int[10];
int j,q,min,k,u;
[Link]("Enter the array element: ");
for(j=0;j<=9;j++)
{
a[j]=[Link]();
}
[Link]("\nThe original array is: ");
for(j=0;j<=9;j++)
{
[Link](a[j]+",");
}
for(j=0;j<=9;j++)
{
q=j;
min=a[j];
for(k=j+1;k<=9;k++)
{
if(a[k]<min)
{
min=a[k];
q=k;
}
}
u=a[j];
a[j]=a[q];
a[q]=u;
59
}
[Link]("\nThe sorted array is: ");
for(j=0;j<=9;j++)
{
[Link](a[j]+",");
}
}
}

Output :

60
Variable description table

Name Type Purpose


a int To store the array element

q int To store position of min


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

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

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

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

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

Variable description table

Name Type Purpose


a int To store the array element

j int Loop index variable


k int Loop index variable

63

You might also like