C language outputs a subsequence of 0 for all elements in an array

Source: Internet
Author: User

This program uses a time seed to randomly generate 10 integers [-5 ~ 5]. The function is randData (). There is also a function ZeroSubarray () that calculates the subsequence as 0 ().
RandData () is as follows:
[Cpp]
Int arr [10];
Void randData (int a [], int start, int end)
{
Srand (time (NULL ));
For (int I = start; I <= end; ++ I)
A [I] = rand () % 10-5;

Printf ("generate new sequence :");
Print (a, start, end );
Printf ("\ n ");
}

ZeroSubarray () is as follows:
[Cpp]
Void ZeroSubarray (int a [], int size ){
If (size <= 0)
Perror ("error array size ");
Int sum = 0;
Int max =-(1 <31 );
Printf ("************* \ n ");
For (int cur = 0; cur <size; cur ++)
{
Sum = 0;
For (int j = cur; j <size; j ++)
{
Sum + = a [j];
If (sum = 0)
{
While (cur <= j)
{
Printf ("% d", a [cur ++]);
}
Printf ("\ n ************* \ n ");
}
}
}
}
Main function:
[Cpp]
Void main ()
{
RandData (arr, 0, 9 );
ZeroSubarray (arr, 10 );
Printf ("\ n ");
}
The running result is as follows:

 

Related Article

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.