Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main()
- {
- int arr[100],n,i,j,temp;
- printf("Enter the size of array: ");
- scanf("%d",&n);
- printf("Enter the array elements: ");
- for(i=0;i<n;++i)
- {
- scanf("%d",&arr[i]);
- }
- for(i=1;i<n;++i)
- {
- for(j=0;j<(n-i);++j) /// (n-i) means we won't sort the elements which we already sorted , you can write n-1 too
- {
- if(a[j]>arr[j+1])
- {
- temp=arr[j];
- arr[j]=arr[j+1];
- arr[j+1]=temp;
- }
- }
- }
- printf("\nArray after sorting: ");
- for(i=0;i<n;++i)
- {
- printf("%d ",arr[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement