Difficulty in problem : SC31

Can anyone explain why am I getting an output as garbage integer?

#include<stdio.h>
#include<stdlib.h>
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int n;
        scanf("%d",&n);
        int s[n][10];
        int i,j;
        for(i=0;i<n;i++)
        {
            for(j=0;j<10;j++){
                scanf("%d",&s[i][j]);
            }
        }
        for(i=0;i<n-1;i++){
            for(j=0;j<10;j++){
                if((s[i][j]==1)&&(s[i+1][j]==0))
                    s[i+1][j]=1;
                else if((s[i][j]==1)&&(s[i+1][j]==1))
                    s[i+1][j]=0;
            }
        }
        int cnt=0;
        for(j=0;j<10;j++){
            cnt=cnt+s[n-1][j];
        }
        printf("%d\n",&cnt);
    }
    return 0;
}

Always read the compiler warnings :slight_smile:

aayush_bdn-SC31.cpp:29:27: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int*’ [-Wformat=]
         printf("%d\n",&cnt);

2 Likes

okay but still I am getting a garbage value and when I write
int cnt=0;
for(j=0;j<10;j++){
if(s[n-1][j]==1)
cnt+=1;
}
I am getting output as 0. This is basically a XOR gate implimentation so can you tell me what is wrong in this approach.

Post whole code, please :slight_smile:

Edit: Or better still, a link to your Submission - I can’t see any from you for SC31.

https://www.codechef.com/submit/SC31

#include<stdio.h>
#include<stdlib.h>
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int n;
        scanf("%d",&n);
        int s[n][10];
        int i,j;
        for(i=0;i<n;i++)
        {
            for(j=0;j<10;j++){
                scanf("%d",&s[i][j]);
            }
        }
        for(i=0;i<n-1;i++){
            for(j=0;j<10;j++){
                if((s[i][j]==1)&&(s[i+1][j]==0))
                    s[i+1][j]=1;
                else if((s[i][j]==1)&&(s[i+1][j]==1))
                    s[i+1][j]=0;
            }
        }
        int cnt=0;
        for(j=0;j<10;j++){
            if(s[n-1][j]==1)
                cnt+=1;
        }
        printf("%d\n",cnt);
    }
    return 0;
}

That’s not a link to a submission - this is the link to your only submission for SC31, and it gets AC.

1 Like

okay sorry :sweat_smile:
https://www.codechef.com/viewsolution/33206840