Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

write a program to sort the elements in a given array in c
language

Answer Posted / m. ahsan

#include <stdio.h>
#include <conio.h>

//Sorting an array with a single FOR loop. No complex coding and testing with multiple array sizes.

int main()
{ clrscr();

int xlist[5]={5,3,4,1,2};

int i,temp;

for (i=0;i<4;)
{
if (xlist[i]<xlist[i+1])
i++;
else
{ temp=xlist[i];
xlist[i]=xlist[i+1];
xlist[i+1]=temp;
i=0;
}
}

for (i=0;i<5;i++)
{ printf("%d ",xlist[i]); }

getch();
return 0;
}

Is This Answer Correct ?    14 Yes 15 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is malloc calloc and realloc in c?

1332


can we implement multi-threads in c.

1131


What are structure members?

1094


What does %d do?

1279


What are formal parameters?

1121


Define VARIABLE?

1167


What is #define size in c?

1197


What are different storage class specifiers in c?

1096


What are the disadvantages of external storage class?

1061


Is there any possibility to create customized header file with c programming language?

1065


What is the symbol indicated the c-preprocessor?

1251


What is the difference between NULL and NUL?

1293


Explain what is page thrashing?

1101


Is null always equal to 0(zero)?

1037


What are predefined functions in c?

1100