answersLogoWhite

0


Best Answer

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int n,i,j,temp,a[50];

printf("Enter how many elements=");

scanf("%d",&n);

printf("Enter %d elements",n);

for(i=1;i<=n;i++)

{

scanf("%d",&a[i]);

}

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

{

for(j=1;j<=n-1;j++)

{

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

{

temp=a[j];

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

a[j+1]=temp;

}

}

}

printf("\nSorted Array:\n");

for(i=1;i<=n;i++)

{

printf("\n%d",a[i]);

}

getch();

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

class bubble

{

public void main(int a[])

{

int t,l,i,j;

l=a.length;

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

for (i=0;i<l;i++)

{

System.out.print(a[i] +",");

}

for (i=0;i<l-1;i++)

{

for (j=0;j<l-1;j++)

{

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

{

t=a[j];

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

a[j+1]=t;

}

System.out.println("the sorted array is ");

for(i=0;i<l;i++)

{

system.out.print(a[i] +",");

}}

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

Search the unsorted array for the largest element and swap with the last element. Reduce the upper bound of the array by one element, thus creating a sorted array at the end of the array. Repeat until there is only one element in the unsorted array (the smallest element), at which point the array is sorted.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a program to sort an array using selection sort?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.


Write c program to find median?

If you are using an array : sort using qsort() then take middle element.


How do you write an assembly language program to find the sum of n numbers using array?

write an assembly language program to find sum of N numbers


You want to write a simple without using pointer or array c program which will print greatest number when you give 20 number?

i want to write a simple without using pointer or array c program which will print greatest number when i give 20 number .........How far have you gotten so far?


Would you Write c plus plus program using array for Fibonacci number?

You can write a C++ fib pro using arrays but the problem is the prog becomes very complicated since u need to pass the next adding value in an array.....


Write a c program to reverse an array without using another array?

public static int[] reverseArray(int[] array) { int i = 0, j = array.length - 1; for (i = 0; i &lt; array.length / 2; i++, j--) { int temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; }


How do you write a C Program to fill up an Integer Array?

Reference:cprogramming-bd.com/c_page1.aspx# array programming


Could you Write a program for 8086 microprocessor that displays on the monitor the average of 2 numbers from an array?

How to write a program for mouse in microprocessor?


Write a java program to maintain bank details using packages?

Use the Array Package. if you need help - add me on msn james_mc_123@hot dkjdkdjd mail.comp


How do you write a program in C to find and display the sum of each row and column of a 2 dimensional array of type float?

array type


Write an Algorithm to delete a last element from the array?

// Assuming you dynamically allocated this array using "new"... delete array[arraysize - 1]; arraysize--;


Write a c program to find the maximum value of 25 element in an array?

int findMax(int *array) { int max = array[0]; for(int i = 1; i &lt; array.length(); i++) { if(array[i] &gt; max) max = array[i] } return max; }