Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- void swap(int* a, int* b);
- int main(){
- int first=0,last=0,n=0,i=0,j=0,arr[15];
- printf("enter the size of the array(less than 15): ");
- scanf("%d",&n);
- printf("enter the array members: ");
- for(i=0;i<n;i++){
- scanf("%d",&arr[i]);
- }
- printf("\nthe entered array: ");
- for(i=0;i<n;i++){
- printf("%d ",arr[i]);
- }
- last=(n-1);
- //bubble sort
- for(i=last;i>first;i--){
- for(j=first;j<last;j++){
- if(arr[j]>arr[j+1]){
- swap(&arr[j],&arr[j+1]);
- }
- }
- }
- printf("\nthe sorted array: ");
- for(i=0;i<n;i++){
- printf("%d ",arr[i]);
- }
- return 0;
- }
- void swap(int* a, int* b){
- *a=*a + *b;
- *b=*a-*b;
- *a=*a-*b;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement