main()
{
int a[100],i,j,n,temp,l;
printf("Enter the number of element you want to insert -----> ");
scanf("%d",&n);
printf("Now, enter %d integers in the array \n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
printf("-------------------------------\n");
for(j=i+1;j<n;j++)
{
printf("Check %d > %d \n",a[i],a[j]);
if(a[i]>a[j])
{
printf("%d > %d now swap both the values \n",a[i],a[j]);
temp=a[i];
a[i]=a[j];
a[j]=temp;
printf("a[%d] = %d and a[%d]= %d\n",i,a[i],j,a[j]);
}
}
if(i<n-1){
printf("After this the result is---> ");
for(l=0;l<n;printf("%d ",a[l]),l++);
printf("\n");}
}
printf("Now the final result is given below :-- \n");
for(i=0;i<n;i++)
printf("%d ",a[i]);
getch();
}
No comments:
Post a Comment