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;
}
ssjgz
May 20, 2020, 5:05pm
2
Always read the compiler warnings
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.
ssjgz
May 21, 2020, 9:05am
4
Post whole code, please
Edit: Or better still, a link to your Submission - I can’t see any from you for SC31 .
ssjgz
May 21, 2020, 9:30am
6
That’s not a link to a submission - this is the link to your only submission for SC31, and it gets AC.
1 Like