+ 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

26th Jan 2019, 3:24 PM
Purvaja Durga
Purvaja Durga - avatar
7 Answers
+ 1
For example, you could do: int a [100]; for(int i =0; i< 100; i++){ a[i] = i; }
26th Jan 2019, 4:12 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 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.
27th Jan 2019, 6:02 AM
SURESH S
SURESH S - avatar
0
Myexamdurga😉😎 You did not initialize 'n' and you did not initialize 'a'.
26th Jan 2019, 3:52 PM
Ulisses Cruz
Ulisses Cruz - avatar
0
Why to initialize,we can scan (scanf)right?
26th Jan 2019, 4:06 PM
Purvaja Durga
Purvaja Durga - avatar
0
You never used scanf to initialize 'a' in the code
26th Jan 2019, 4:08 PM
Ulisses Cruz
Ulisses Cruz - avatar
0
a[100]
26th Jan 2019, 4:09 PM
Purvaja Durga
Purvaja Durga - avatar
0
That is a declaration not an initialization.
26th Jan 2019, 4:09 PM
Ulisses Cruz
Ulisses Cruz - avatar