kingstertime

Untitled

Jan 11th, 2021
521
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <assert.h>
  2. #include <limits.h>
  3. #include <math.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. int
  8. main (int argc, char *argv[])
  9. {
  10.   assert (argc - 1 == 1);
  11.   long n;
  12.   {
  13.     char *tail;
  14.     n = strtol (argv[1], &tail, 0);
  15.     assert (tail > argv[1]);
  16.     assert (*tail == '\0');
  17.   }
  18.  
  19.   assert (n >= 1);
  20.   assert (n <= sqrt (LONG_MAX));
  21.   const int width = (int)ceil (2 * log (1 + n) / log (10));
  22.  
  23.   long i;
  24.   for (i = 1; i <= n; i++) {
  25.     long j;
  26.     for (j = 1; j <= n; j++) {
  27.       printf (" %*ld", width, i * j);
  28.     }
  29.     putchar ('\n');
  30.   }
  31.  
  32.   return 0;
RAW Paste Data