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 zero based addressing?
How do you define CONSTANT in C?
How to delete a node from linked list w/o using collectons?
Why do we write return 0 in c?
Explain void pointer?
When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?
What are disadvantages of C language.
Why is c platform dependent?
write a c program to find the largest and 2nd largest numbers from the given n numbers without using arrays
What are the 5 organizational structures?
Why does not c have an exponentiation operator?
How will you print TATA alone from TATA POWER using string copy and concate commands in C?
List the different types of c tokens?
What is pivot in c?
What is the data segment that is followed by c?