100% prog to arrange numbers in increasing order (sorting)
#include<stdio.h>
void main()
{
int i,j,k,temp,chinna,a[ ]={42,60,26,55,34,28}; //{3,8,2,-1,4};
printf("\n before sorting a[ ]=");
for(i=0;i<6;i++)
{
printf("%5d",a[i]);
}
for(i=0;i<6;i++)
{
chinna=a[i];
for(j=i+1;j<6;j++)
{
if(a[j]<chinna)
{
chinna=a[j];
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
printf("\n after mini-stage %d, a[ ]=",j);
for(k=0;k<6;k++)
{
printf("%5d",a[k]);
}
}
}
printf("\n after sorting a[ ]=");
for(i=0;i<6;i++)
{
printf("%5d",a[i]);
}
}// end of main
/*this may not be the efficient way of writing but we get the desired output. u plz try to print in decreasing order*/
ఔట్పుట్ తెరమీద
before sorting a[ ]= 42 60 26 55 34 28
after mini-stage 1, a[ ]= 42 60 26 55 34 28
after mini-stage 2, a[ ]= 26 60 42 55 34 28
after mini-stage 3, a[ ]= 26 60 42 55 34 28
after mini-stage 4, a[ ]= 26 60 42 55 34 28
after mini-stage 5, a[ ]= 26 60 42 55 34 28
after mini-stage 2, a[ ]= 26 42 60 55 34 28
after mini-stage 3, a[ ]= 26 42 60 55 34 28
after mini-stage 4, a[ ]= 26 34 60 55 42 28
after mini-stage 5, a[ ]= 26 28 60 55 42 34
after mini-stage 3, a[ ]= 26 28 55 60 42 34
after mini-stage 4, a[ ]= 26 28 42 60 55 34
after mini-stage 5, a[ ]= 26 28 34 60 55 42
after mini-stage 4, a[ ]= 26 28 34 55 60 42
after mini-stage 5, a[ ]= 26 28 34 42 60 55
after mini-stage 5, a[ ]= 26 28 34 42 55 60
after sorting a[ ]= 26 28 34 42 55 60
కామెంట్లు
కామెంట్ను పోస్ట్ చేయండి
దయచేసి మీ సలహాలను సూచనలను స్పష్టంగా పేర్కొనగలరు. plz see that ur comments are 'acceptable' in a value based society.