SCHOOL OF CODE BUILDERS
Learn To CODE. Become A DEVELOPER.
Pages
HOME
DATA STRUCTURES
STRINGS
ARRAYS
MATRIX
BINARY TREES
LINKED LIST
STACK
QUEUE
SORTING
SEARCHING
C
PYTHON
PSEUDOCODE
CONTEST PROBLEMS
ALGORITHMS
PATTERNS
PHP
C PUZZLES
C INTERVIEW QUESTIONS
JAVA
C++
HASHING
RECURSION
BASIC C PROGRAMS
TCS-CODEVITA
FACEBOOK
CONTACT US
C program to arrange numbers in ascending order
C program to arrange numbers in ascending order
Output:
Enter the number of elements to sort:
5
Enter the elements to sort:
2 3 1 5 4
The sorted array is:
1 2 3 4 5
Implementation:
#include
#include
#include
void swap(int *x,int *y) { int temp; temp=*x; *x=*y; *y=temp; } int main(void) { int *a,n,i,j; printf("Enter the number of elements to sort:\n"); scanf("%d",&n); a=(int*)malloc(sizeof(int)*n); printf("Enter the elements to sort:\n"); for(i=0;i
*(a+j)) { swap((a+i),(a+j)); } } } /* printint the sorted array */ printf("The sorted array is:\n"); for(i=0;i
PREVIOUS
NEXT
HOME