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]);
}
After replacing 7 to n in loops, there is no segmentation fault but output is not in sorted numbers.
The main problem lies in the following lines of the program.
for(int k=0;k<5;k++)
{
while(b[k]>0)
{
b[k]–;
o[b[k]]=r[k];
}
}
for(int l=0;l<n;l++)
printf("%d sorted array\n", o[l]);