Decreasing String:Cannot find error

My c code for this for the problem :

 #include<stdio.h>
    
    int main()
    {
            char alpha[27];
            int t,k,q,r,i;
    
            for(i='z';i>='a';--i)
                alpha['z'-i]=i; // storing in descending order
            
            alpha[i]='\0';
    
            scanf("%d",&t);
    
            while(t--)
            {
                    scanf("%d",&k);
    
                    q=k/25;r=k%25;
    
    
                    for(i=25-r;i<=25 && r!=0 ;++i)
                        printf("%c",alpha[i]);
   
                    while(q--)
                        printf("%s",alpha);
    
                    printf("\n");
    
            }
    
            return 0;
    }

Now i saw many solutions and found that my error is that particular loop as marked above . But i am unable to find that error. Checked many test cases against correct solutions but all answers came out to be same . Please Help.

i think even this could be an error…

alpha[i]='\0';

just check!!!

1 Like
//