Computer Science, asked by rajpoot2005, 2 months ago

Write a program to store 10 numbers in a single dimensional array and arrange them in ascending order using bubble sort. Only quality answers required. Also attach the program successfully compiled and the output.​

Answers

Answered by Anonymous
74

The given co‎de is written in Java:

import java.util.*;

public class Bubble_Sort    {

   public static void main(String args[])  {

       Scanner sc=new Scanner(System.in);

       int a[]=new int[10],n=10,i,j,x;

       System.out.println("Enter 10 numbers in the array..");

       for(i=0;i<n;i++)    {

           System.out.print(">> ");

           a[i]=sc.nextInt();

       }

       System.out.println("Given Array: "+Arrays.toString(a));

       System.out.println("Sorting the array...");

       for(i=0;i<n;i++)    {

           for(j=0;j<n-i-1;j++)    {

               if(a[j]>a[j+1]){

                   x=a[j];

                   a[j]=a[j+1];

                   a[j+1]=x;

               }

           }

       }

       System.out.println("Array Sorted Successfully.");

       System.out.println("Sorted Array: "+Arrays.toString(a));

       sc.close();

   }

}

Attachments:
Answered by unknown7033
0

Answer:

is yoir answer hope it helps you

Attachments:
Similar questions