Advertisement
_fur

_fur | C Charisma Tubagus Setyobudhi

Dec 10th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #define ABS(x) ((x) < 0 ? -(x) : (x))
  3.  
  4. int main(void)
  5. {
  6.         int i;
  7.         int d[2], m[2], y[2];
  8.         int jd[2];
  9.  
  10.         printf("Date-1 (dd-mm-yyyy): ");
  11.         scanf("%d-%d-%d", &d[0], &m[0], &y[0]);
  12.         printf("Date-2 (dd-mm-yyyy): ");
  13.         scanf("%d-%d-%d", &d[1], &m[1], &y[1]);
  14.  
  15.         for (i = 0; i < 2; i++)
  16.                 jd[i] = (1461 * (y[i] + 4800 + (m[i] - 14) / 12)) / 4
  17.                       + (367 * (m[i] - 2 - 12 * ((m[i] - 14) / 12))) / 12
  18.                       - (3 * ((y[i] + 4900 + (m[i] - 14) / 12) / 100)) / 4
  19.                       + d[i] - 32075;
  20.  
  21.         printf("Days difference : %d\n", ABS(jd[1] - jd[0]));
  22.  
  23.         return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement