#include #include /* Verification code of pair sequence algorithm Translated from original BASIC program to C algorithm modified: - D loop eliminated - C is set as constant 2 and does not change - Calculation stops when the length of the sequence exceeds maxlength */ const int maxlength = 200; int main(void) { int a[maxlength], b[maxlength], c = 2, e, f, h, i, j, k; int len=2; a[0]=0; b[0]=0; a[1]=1; b[1]=1; a[2]=2; b[2]=1; for (f = len; f >= 0; f--) { for (h = 0; h< f; h++) { printf("(%d,%d)", a[h], b[h]); } printf("(%d,%d)[%d]\n",a[f], b[f], c); if (!b[f]) { for (h = 0; h <= f; h++) { if (a[f-h] < a[f] || !a[f]) { k = 0; i = h; h = f; } } } else { for (h = 1; h <= f; h++) { if (a[f-h] < a[f] && b[f-h] < b[f]) { k = a[f]-a[f-h]; i = h; h = f; } } } for (j = 1; j <= c * i; j++) { a[f] = a[f-i] + k; b[f] = b[f-i]; f++; if ( f > maxlength ) { return 0; } } } return 0; }