#include int main(int argc, char *argv[]) { int n, n1, a, b, c; /* Prints "n, (a,b)" where (a,b) is the n-th ordered pair of natural numbers under the following enumeration of the ordered pairs of nat. numbers: before iff (x+y < w+z) or (x+y==w+z and x>w) */ if (argc != 2) { printf("\n One argument--integer expected! Exit.\n"); return 1; } n = atoi(argv[1]); n1 = n; if (n == 0) { a = 0; b = 0; } else { c = 1; while (c <= n) { n = n - c; c ++; } /* Now c-1 equals the # of executions of the loop's body; i.e., c-1 is the number of the diagonal that (a,b) is in. */ a = c - n - 1; b = n; /* b is the offset of (a,b) in diagonal number c-1; a+b equals c-1. */ } printf(" n = %d : (%d, %d)\n", n1, a, b); return 0; }