SIGSEGV:NUKES. Can someone please point out why my code gives SIGSEGV

,

Here’s the code…

/*NUKES*/

#include<stdio.h>

int main(void)
{
    unsigned long long a,n,k;
    unsigned int arr[105]={0};
    unsigned int i=0,j;

    scanf("%llu%llu%llu",&a,&n,&k);
    while(a)
    {
        arr[i++] = a%(n+1);
        a/=(n+1);
    }

    for(j=0;j<k;j++)
    {
        if(j!=(k-1))
            printf("%u ",arr[j]);
        else
            printf("%u",arr[j]);
    }
    printf("\n");
    return 0;
}

The error is because of the condition in the loop

while(a)
{
 arr[i++]=a%(n+1);
 a/=(n+1);
}

The correction:

while(i<k)
{
    arr[i++] = a%(n+1);
    a/=(n+1);
}

I have corrected it: http://www.codechef.com/viewsolution/4166719

If you still have any problem comment below.

Happy Coding!

//