Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to input 14 numbers and find the lengths of the biggest zero sequence in C

1 Answer

0 votes
#include <stdio.h> 

int main(void)
{
    int max_zero_count = 0, zero_counter = 0, n, i = 1 ;
    
    while (scanf("%i", &n) == 1 && i <= 13) // run 14 times: run scanf() before check i <= 13
    {
        if (n == 0)
        {
            zero_counter++;
            if (zero_counter > max_zero_count) 
                max_zero_count = zero_counter;
        }
        else 
            zero_counter = 0;
        i++;
    }
    printf("Max zeros sequence length: %i\n", max_zero_count);
    
    return 0;
}

/* 
run:
1
6
5
0
0
0
4
5
0
0
0
0
3
8
Max zeros sequence length: 4

*/




answered Sep 18, 2014 by avibootz
...