You are on page 1of 1

visit-www.Codes2u.

com
# include <stdio.h>
#include<conio.h>
void main()
{
int a[10],b[10],c[100],i,j,n,m;
printf("enter the length of array");
scanf("%d",&n);
printf("enter ur array");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("enter the max element of the array");
scanf("%d",&m);
for(i=1;i<=m;i++)
c[i]=0;
for(j=1;j<=n;j++)
c[a[j]]=c[a[j]]+1;
for(j=1;j<=m;j++)
c[j]=c[j]+c[j-1];
for(j=n;j>=1;j--)
{
b[c[a[j]]]=a[j];
c[a[j]]=c[a[j]]-1;
}
printf("sorted array is");
for(i=1;i<=n;i++)
printf("\n\t%d",b[i]);
getch();
}

You might also like