Use C ++ to write a Boolean function. This function obtains a value a [n] (N ≥1) with 0 or 1 as the original value ), determine whether the size of each continuous sequence with 1 is an even number.

Source: Internet
Author: User
This function obtains a value a [n] (N ≥1) with 0 or 1 as the original value, and determines whether the size of each continuous sequence with 1 is an even number.

# Include <iostream>

Using namespace STD;

Bool fun (int * a, int N)

{

Int I = 0; int coun = 0;

While (I! = N)

{

If (A [I] = 1)

{

Coun ++;

I ++;

}

Else {

I ++;

If (coun % 2! = 0)

Return false;

Coun = 0;

}

}

If (coun % 2 = 0) // think about why

Return true;

Return false;

}

Int main ()

{

Cout <"input the size of the array:" <Endl;

Int size;

Cin> size;

Int A [100];

Cout <"input the value:" <Endl;

For (INT I = 0; I <size; I ++)

{

Cout <"A [" <I <"]" <":";

Cin> A [I];

}

If (fun (A, size ))

Cout <"there are all double" <Endl;

Else

Cout <"there are not all double" <Endl;

Cout <"Hello world! "<Endl;

Return 0;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.