(3)programme for shorting
import java.util.Scanner;class Mittu
{
public static void main(String []args)
{
Scanner s=new Scanner(System.in);
int i,t,j,n;
System.out.println("enter size of array");
n=s.nextInt();
int x[]=new int[n];
System.out.println("enter "+n+" 5elements");
for(i=0;i<n;i++)
for(i=0;i<n;i++)
x[i]=s.nextInt();
for(j=0;j<n-1;j++)
for(i=j+1;i<n;i++)
if(x[j]>x[i])
{
t=x[i];
x[i]=x[j];
x[j]=t;
}
System.out.println("after shorting");
for(i=0;i<n;i++)
System.out.println(x[i]);
}
}
output
enter size of array10
enter 10 5elements
8
6
4
2
9
7
5
3
1
10
after shorting
1
2
3
4
5
6
7
8
9
10
No comments:
Post a Comment