+ 1
Can anyone please find the error in the code?
The code is #include<stdio.h> #include<string.h> int main() { int a[100]; int t,i,n,count=0; scanf("%d",&t); for(i=0;i<t;i++) { scanf("%d",&n); } for(i=0;i<n;i++) { if((a[i]==0)&&(a[i+1]==1)&&(a[i+2]==0)) count++; } printf("%d",count); } Input : 2 6 010001 7 0101010 Output: 1 3 https://code.sololearn.com/cm83Lj5TOvaU/?ref=app
7 Answers
+ 1
For example, you could do:
int a [100];
for(int i =0; i< 100; i++){
a[i] = i;
}
+ 1
for(i=0;i<t;i++)
{
scanf("%d",&a[i]);
}
and then you didn't get any value of n.so you t value in next for loop
for(i=0;i<t;i++)
{
if(statement)
count++;
}
use the logic get the correct o/p.dont use n.
0
Myexamdurga😉😎
You did not initialize 'n' and you did not initialize 'a'.
0
Why to initialize,we can scan (scanf)right?
0
You never used scanf to initialize 'a' in the code
0
a[100]
0
That is a declaration not an initialization.