Created
May 25, 2022 12:53
-
-
Save Dbhardwaj99/c2e02d71915aeae2c9d01e54f175e8b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
void main() | |
{ | |
int i,j,temp,p,n; | |
int ar[50]; | |
printf("Enter the size of an array"); | |
scanf("%d",&n); | |
printf("Enter the array elements: "); | |
for(i=0;i<n;++i) | |
{ | |
scanf("%d",&ar[i]); | |
} | |
for(i=1;i<n;++i) | |
{ | |
for(j=0;j<(n-i);++j) | |
{ | |
if(ar[j]>ar[j+1]) | |
{ | |
temp=ar[j]; | |
ar[j]=ar[j+1]; | |
ar[j+1]=temp; | |
} | |
} | |
} | |
p=ar[n-2]; | |
for(i=n-2;i>0;i--) | |
{ | |
ar[i]=ar[i-1]; | |
} | |
ar[0]=p; | |
printf("%d",ar[i]); | |
printf("\nArray after sorting: "); | |
for(i=0;i<n;++i) | |
{ | |
printf("%d ",ar[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment