#include<stdio.h>

void counting_sort(int a[], int r[]);

//void printarray(int a[]);

int main()

{

int a[55],i,n=7,j,k,l,range=5,r[33];

printf(" Enter the total number for sorting");

scanf("%d", &n);

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

{

printf(“Enter the number for sorting\n”);

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

}

for(j=0;j<range;j++)

{

printf(“Enter the number for range\n”);

scanf("%d",&r[j]);

}

```
counting_sort(a,r);
//printarray(a);
```

}

void counting_sort(int a[33], int r[33])

{

int key, o[33], count, sum, b[77];

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

{

count=0;

key=r[i];

for(int j=0;j<7;j++)

{

if(a[j]==key)

count++;

}

b[i]=count;

b[i]= b[i]+sum;

sum=b[i];

//b[i+1]= b[i]+b[i+1];

printf(" %d after adding is %d \n",r[i], b[i]);

}

for(int k=0;k<5;k++)

{

while(b[k]>0)

{

b[k]–;

o[b[k]]=r[k];

}

}

**for(int l=0;l<7;l++)
printf("%d sorted array", o[l]);**

` }`