Skip to content

Instantly share code, notes, and snippets.

@Dbhardwaj99
Created May 25, 2022 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dbhardwaj99/c2e02d71915aeae2c9d01e54f175e8b7 to your computer and use it in GitHub Desktop.
Save Dbhardwaj99/c2e02d71915aeae2c9d01e54f175e8b7 to your computer and use it in GitHub Desktop.
#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