#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int n, a, b; /* Input is "a b" for some natural numbers a,b. The output is "n" where n is the number of the ordered pair (a,b) under the following enumeration of the ordered pairs of nat. numbers: <x,y> before <w,z> iff (x+y < w+z) or (x+y==w+z and x<w) */ if (argc != 3) { printf("\n Two arguments expected! Exit.\n"); return 1; } a = atoi(argv[1]); b = atoi(argv[2]); if (a < 0 || b < 0) { printf("\n Two natural numbers expected! Exit.\n"); return 2; } if (a == 0 && b == 0) { n = 0; } else { n = (a+b)*(a+b+1)/2 + b; } printf(" n = %d\n", n); return 0; }