import java.io.*;
class Store
{
public static void main (String[] args)throws Exception
{
DataInputStream d=new DataInputStream(System.in);
System.out.println("Enter no. of Programs:");
int n=Integer.parseInt(d.readLine());
int[] p=new int[n];
int[] a=new int[n];
int i;
System.out.println("Enter the programs with length:");
for(i=0;i<=n-1;i++)
{
System.out.print("Program"+(i+1)+":");
p[i]=Integer.parseInt(d.readLine());
System.out.println();
a[i]=i+1;
}
for(i=n-2;i>=0;i--)
{
for(int j=0;j<=i;j++)
{
if(p[j]>p[j+1])
{
int temp=p[j];
p[j]=p[j+1];
p[j+1]=temp;
int t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
System.out.println("The Best Ordering is");
for(i=0;i<=n-1;i++)
{
System.out.println("Program"+a[i]+":"+p[i]);
}
}
}
/*Output:
Enter no. of Programs:
3
Enter the programs with length:
Program1:5
Program2:10
Program3:3
The Best Ordering is
Program3:3
Program1:5
Program2:10
Process completed.
*/
3 comments:
can i get c source code of this topic??
can u provide the c source code of this program
Mu me lega Babu
Post a Comment