Xiao Ming likes maths very much, one day when he is doing mathematics homework, ask to calculate 9~16 and,// He immediately wrote the correct answer is 100. But he was not satisfied with it, and he wondered how many successive positive sequences of sum were 100 (including at least two numbers). Before long, he got another set of consecutive positive numbers and a sequence of 100:18,19,20,21,22. Now give you the question, can you also quickly find all and for the continuous positive sequence of s?//good//////////////////////////////////////////outputs all successive positive sequences for S. Sequence in order from small to large, the sequence of starting numbers from small to large order//the Bull Sword Point offer perfect through. #include <iostream>using namespace std;void grial (int x) {int i = 0; int A;int b;int Data[x];int k = 0; for (i=1;i<x;i++) {int sum = 0;for (int j = i;j<x;j++) {sum+=j;if (sum==x) {A=i;b=j;bre AK;} if (sum>x) {break;}} if (sum==x) {for (int j = a;j<=b;j++) {data[k++]=j;}}} for (i = 0;i<k;i++)//equivalent to Vector<vector<int> > in the offer of the sword. {cout<<data[i]<< " ";} Cout<<endl;} int main () {grial (9); return 0;}
C + + outputs all and consecutive positive sequences of S (Ox-Guest sword offer)