More actions
({CREATE}) |
imported>h94418 No edit summary |
||
| Line 1: | Line 1: | ||
#include | #include <stdio.h> | ||
void bubbleSort(int A[], int N); | void bubbleSort(int A[], int N); | ||
int main() | int main() | ||
{ | { | ||
int i; | |||
int a[5]; | |||
for(int j=0;j<5;j++){ | |||
scanf("%d",&a[j]); | |||
} | |||
bubbleSort(a,5); | |||
for (i=0;i<5;i++) | |||
printf(“%d\n”,a[i]); | |||
return 0; | |||
} | } | ||
void bubbleSort(int A[], int N) | void bubbleSort(int A[], int N) | ||
{ | { | ||
int temp,i, j; | |||
for (i=N-1;i>=1;i--) | |||
for (j=1;j<=i;j++) | |||
if (A[j-1]>A[j]) { | |||
temp=A[j-1]; | |||
A[j-1]=A[j]; | |||
A[j]=temp; | |||
} | |||
} | } | ||
Latest revision as of 14:52, 18 May 2017
#include <stdio.h>
void bubbleSort(int A[], int N);
int main()
{
int i;
int a[5];
for(int j=0;j<5;j++){
scanf("%d",&a[j]);
}
bubbleSort(a,5);
for (i=0;i<5;i++)
printf(“%d\n”,a[i]);
return 0;
}
void bubbleSort(int A[], int N)
{
int temp,i, j;
for (i=N-1;i>=1;i--)
for (j=1;j<=i;j++)
if (A[j-1]>A[j]) {
temp=A[j-1];
A[j-1]=A[j];
A[j]=temp;
}
}