Computer Science, asked by Naresh5551, 1 year ago

write a prgm to sort an array with bubble sort

Answers

Answered by ep138820
1

/* Bubble sort code */

#include <stdio.h>

int main()

{

int array[100], n, c, d, swap;

printf("Enter number of elements\n");

scanf("%d", &n);

printf("Enter %d integers\n", n);


Answered by Anonymous
0

import java.util.*;

class bubble_sort

{

int n;

int arr[]=new int[n];

int b[]=new int[n];

public static void main(String args[])

{

accept();

}

void accept()

{

Scanner sc=new Scanner(System.in);        

System.out.println("Enter a number of elements");

n=sc.nextInt();

System.out.println("Enter the array elements");

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

{

arr[i]=sc.nextInt();

b[i]=arr[i];

}

sort();

}

void sort()

{

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

{

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

{

if(arr[j]>arr[j+1])

{

int temp=arr[j];

arr[j]=arr[j+1];

arr[j+1]=temp;

}

}

}

disp();

}

void disp()

{

System.out.println("The elements in the array are arranged in acending:");

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

{

System.out.println(arr[i]);

System.out.println(b[i]);

}

}

}

Similar questions