# Sorting of Array in C

## Sorting of Array in C Language

In this page we will look into a coding question where we will learn how to sort the array in C programming language. There are many sorting techniques to sort the array like quick sort, merge sort, bubble sort, insertion sort of them is scripted below.
There might be different approach to solve this question, one you will find here. If your approach is bit different post it onto the comment section. ### Problem Statement

Write a program in C programming language where you need to find the sort the elements of array in ascending order.

Input Format
-First line will contain the number of elements present in the array.
-Second line will contain the elements of array

Output Format

-Output contain the space separated sorted elements in ascending order

Sample Test Case : 1

Input
9
4 2 1 6 8 2 9 3 5 7

Output
1 2 3 4 5 6 7 8 9

Sample Test Case : 2

Input
8
414 55 6 745 -215 663 -54 68

Output
-215 -54 6 55 68 414 663 745 ### Program for sorting the elements of c in ascending order

Run

```#include<stdio.h>
int main()
{
int a;
int n, sum, temp;
int i, j;
scanf("%d",&n);
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
for(i=0; i<n; i++)
{
for(j=i+1; j<n; j++) { if(a[i]>a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
for(i=0; i<n; i++)
{
printf("%d ",a[i]);
}
return 0;
}

```

### Output:

`55 2 3 1 41 2 3 4 5 `

## Learn About Arrays in C

Click on the below button to learn about in C Programming Language

Learn Arrays in C

## Learn Data Structures

Click on the below button to study more Data Structure

Learn Data Structures