#include
int main(){
int s,i,j,temp,a[20];
printf("\n Please Enter size of an array :");
scanf("%d",&s);
printf("\nEnter %d elements in to an array:");
for(i=0;i<=s;i++)
scanf("%d",&a[i]);
for(i=0;i<=s;i++){
for(j=i+1;j=if(a[i]>=a[j]){
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("\nThe array after sorting is: ");
for(i=0;i<=s;i++)
printf(" %d",a[i]);
return 0;
}
has bugs.
ReplyDeleteit should be sonething like this:
#include
#include
int main()
{
int s,i,j,temp,a[20];
printf("Enter size of an array :");
scanf("%d",&s);
printf("Enter %d elements in to an array:",s);
for(i=0;i<=s;i++)
scanf("%d",&a[i]);
for(i=0;i<=s;i++)
{
for(j=i+1;j<=s;j++)
{
if(a[i]>=a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("\nThe array after sorting is: ");
for(i=0;i<=s;i++)
printf(" %d",a[i]);
getch();
}