-2

We need to take inputs upto 10^6 and sort them.

So i intialize whole array for zero on paper this code works but the problem i figure out it is that,Every Array index is not intialized to zero which cause the problem can you help me why every Index of array is not intialized to zero?

int main()
{
      unsigned int j,i=0,k,t=0,n,input,flag;
    unsigned int a[10^6]={0};//with this method still give garbage value
    scanf("%d",&n);
    flag=0;
    for(k=n;k>=1;k--)
        {

            scanf("%u",&input);
            a[input]=a[input]+1;
            if(input>flag)
            {
                flag=input;
            }
        }
        while(i<=flag)
        {
            if(a[i]>0)
            {
              while(a[i])
              {
                  printf("%u\n",i);
                  a[i]=a[i]-1;
              }
            }
            i++;
        }

    return 0;
}

In case you want to know question is here Click here
you can see here i check fresh array for first 25 values and this is the result

Terminator
  • 117
  • 7

1 Answers1

0

The problem was solved by BLUEPIXY in short replies

with using

static unsigned int a[1000001]={0};

in the intialization part.
The code is accpeted.
Execution time=0.19 sec

Terminator
  • 117
  • 7