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
What is malloc calloc and realloc in c?
can we implement multi-threads in c.
What are structure members?
What does %d do?
What are formal parameters?
Define VARIABLE?
What is #define size in c?
What are different storage class specifiers in c?
What are the disadvantages of external storage class?
Is there any possibility to create customized header file with c programming language?
What is the symbol indicated the c-preprocessor?
What is the difference between NULL and NUL?
Explain what is page thrashing?
Is null always equal to 0(zero)?
What are predefined functions in c?