Advertisement
Guest User

count zero

a guest
Feb 21st, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     char arr[105],ch;
  5.     int t,j,i,zero,f,l,sz;
  6.  
  7.     scanf("%d",&t);
  8.  
  9.     for(j=0;j<t;j++)
  10.     {
  11.     scanf("%s",&arr);
  12.     i=0;
  13.     zero=0;
  14.           while((ch=arr[i])!='\0')
  15.           {
  16.           if(ch=='0')
  17.           zero++;
  18.           i++;
  19.           }
  20.           i=0;
  21.           f=0;
  22.           while((ch=arr[i])!='1')
  23.           {
  24.           if(ch=='0')
  25.           f++;
  26.           i++;
  27.           }
  28.           sz=strlen(arr);
  29.           i=sz-1;
  30.           l=0;
  31.           while((ch=arr[i])!='1')
  32.           {
  33.           if(ch=='0')
  34.           f++;
  35.           i--;
  36.           }
  37.  
  38.  
  39.     printf("%d\n",zero-f-l);
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement