Advertisement
feblehober123

last-reply-thread.c

Nov 4th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int ilog10(int n);
  6. /* last-reply-thread: generate replies to max number of comments possible */
  7. int main(int argc, char *argv[])
  8. {
  9.     int postnum;
  10.     int countout = 0;
  11.     int linesize = 0;
  12.  
  13.     postnum = atoi(argv[1]);
  14.     while (countout <= 2000) {
  15.         if (linesize)
  16.             printf(">>%d ", postnum);
  17.         linesize = 0;
  18.         postnum += 1;
  19.         linesize += ilog10(postnum)+1;
  20.         linesize += 3;  // ">>" and space
  21.         countout += linesize;
  22.     }
  23.     return 0;
  24. }
  25.  
  26. int ilog10(int num)
  27. {
  28.         int d = 0;
  29.  
  30.         while (num /= 10)
  31.                 d++;
  32.         return d;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement