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
Differentiate between the expression “++a” and “a++”?
On most computers additional memory that is accessed through an adapter of feature card along with a device driver program. a) user memory b) conventional memory c) expandedmemory d) area
What are the types of functions in c?
write a program in c language to print your bio-data on the screen by using functions.
What is pointer & why it is used?
What is define c?
A function can make the value of a variable available to another by a) declaring the variable as global variable b) Passing the variable as a parameter to the second function c) Either of the two methods in (A) and (B) d) binary stream
Between macros and functions,which is better to use and why?
write a programming in c to find the sum of all elements in an array through function.
What is data structure in c language?
What are structure types in C?
Using functions, write a program that multiplies two arrays. Use the following functions: - Function ReadArray - Function MultiplyArrays - Function DisplayArrays
What is getche() function?
Do string constants represent numerical values?
Explain high-order and low-order bytes.