__Code:-__

in this program first we take three arrays one for input one for output and one for counting the frequency . we initialize the counting array to the zero . and while taking input from the user we will count the frequency of all the elements and store it in the array C . and we will also find the maximum among all the numbers (which we will use for loop condition further ) . after taking input we will have to find the cumulative frequency of the array C (i.e c[i]=c[i]+c[i-1] ) .

#include<stdio.h>

int main()

{

int a[50],b[50],n,k=0,c[10]={0};

printf("Enter the element of the list\n");

scanf("%d",&n);

printf("Enter the number of elements of the list\n");

for(int i=0;i<n;i++)

{

scanf("%d",&a[i]);

// frequency counting

c[a[i]]++;

// finding maximum number in the list

if(k<a[i])

k=a[i];

}

// cumulative frequency

for(int i=1;i<k+1;i++)

{

c[i]=c[i]+c[i-1];

}

// logic

for(int i=n-1;i>=0;i--)

{

int t=c[a[i]];

b[t]=a[i];

c[a[i]]--;

}

// the numbers after sorting are

printf("Sorted list:-\n");

for(int i=1;i<=n;i++)

{

printf("%d ",b[i]);

}

return 0;

}

__Output:-__

Enter the element of the list

7

Enter the number of elements of the list

1 2 1 0 3 2 1

Sorted list:-

0 1 1 1 2 2 3

__Recommended Post:-__

__Hackerearth Problems:-__- Very Cool numbers | Hacker earth solution
- Vowel Recognition | Hackerearth practice problem solution
- Birthday party | Hacker earth solution
- Most frequent | hacker earth problem solution
- program to find symetric difference of two sets
- cost of balloons | Hacker earth problem solution
- Chacha o chacha | hacker earth problem solution
- jadu and dna | hacker earth solution
- Bricks game | hacker earth problem
- Anti-Palindrome strings | hacker earth solution
- connected components in the graph | hacker earth data structure
- odd one out || hacker earth problem solution
- Minimum addition | Hackerearth Practice problem
- The magical mountain | Hackerearth Practice problem
- The first overtake | Hackerearth Practice problem

__Hackerrank Problems:-__Data structure:-- Playing With Characters | Hackerrank practice problem solution
- Sum and Difference of Two Numbers | hackerrank practice problem solution
- Functions in C | hackerrank practice problem solution
- Pointers in C | hackerrank practice problem solution
- Conditional Statements in C | Hackerrank practice problem solution
- For Loop in C | hackerrank practice problem solution

- Program to find cycle in the graph
- Implementation of singly link list
- Implementation of queue by using link list
- Algorithm of quick sort
- stack by using link list
- program to find preorder post order and inorder of the binary search tree
- Minimum weight of spanning tree
- Preorder, inorder and post order traversal of the tree

__Key points:-__

__ MCQs:-__

## 0 Comments