Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int a[100],l,i,j,temp;
- void swap()
- {
- for (i = 0; i <(l-1); i++)
- {
- for (j = 0; j <(l-i-1); j++)
- {
- if (a[j] > a[j+1])
- {
- temp = a[j];
- a[j] = a[j+1];
- a[j+1] = temp;
- }
- }
- }
- printf("The sorted array is:-\n");
- for(i=0;i<l;i++)
- printf("%d\t",a[i]);
- }
- int main()
- {
- printf("Enter the array's limit.");
- scanf("%d",&l);
- printf("Now enter %d elements to fill the array.\n",l);
- for(i=0;i<l;i++)
- scanf("%d",&a[i]);
- swap();
- return 0;
- }
- //Output
- //Enter the array's limit.5
- //Now enter 5 elements to fill the array.
- //9
- //-1
- //1
- //0
- //67
- //The sorted array is:-
- //-1 0 1 9 67
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement