#include <stdio.h>
#include <stdlib.h>
void count(int A[],int k,int n)
{
int i,j;
int B[10],C[15];
for(i=0;i<=k;i++)
{
C[i]=0;
}
for(j=1;j<=n;j++)
{
C[A[j]]= C[A[j]] +1;
}
for(i=1;i<=k;i++)
C[i]= C[i]+C[i-1];
for(j=n;j>=1;j--)
{
B[C[A[j]]] = A[j];
C[A[j]] = C[A[j]] -1;
}
printf("Sorted array is:\n");
for(i=1;i<=n;i++)
{
printf("%d ",B[i]);
}
}
int main()
{
int n,A[15],k=0,i;
printf("Enter n\n");
scanf("%d",&n);
printf("\nEnter ele:");
for(i=1;i<=n;i++)
{
scanf("%d",&A[i]);
if(A[i]>k)
k=A[i];
}
count(A,k,n);
return 0;
}
#include <stdlib.h>
void count(int A[],int k,int n)
{
int i,j;
int B[10],C[15];
for(i=0;i<=k;i++)
{
C[i]=0;
}
for(j=1;j<=n;j++)
{
C[A[j]]= C[A[j]] +1;
}
for(i=1;i<=k;i++)
C[i]= C[i]+C[i-1];
for(j=n;j>=1;j--)
{
B[C[A[j]]] = A[j];
C[A[j]] = C[A[j]] -1;
}
printf("Sorted array is:\n");
for(i=1;i<=n;i++)
{
printf("%d ",B[i]);
}
}
int main()
{
int n,A[15],k=0,i;
printf("Enter n\n");
scanf("%d",&n);
printf("\nEnter ele:");
for(i=1;i<=n;i++)
{
scanf("%d",&A[i]);
if(A[i]>k)
k=A[i];
}
count(A,k,n);
return 0;
}
No comments:
Post a Comment