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
Explain continue keyword in c
a value that does not change during program execution a) variabe b) argument c) parameter d) none
What is the general form of #line preprocessor?
Write a progarm to find the length of string using switch case?
Why we write conio h in c?
What is call by reference in functions?
What is modifier & how many types of modifiers available in c?
Write a program to reverse a linked list in c.
What is c basic?
What is the difference between int main and void main in c?
How can I read a binary data file properly?
What is a class c rental property?
How can I do peek and poke in c?
Is main is user defined function?
How do I round numbers?