Advertisement
cd62131

ConbinationNumber

Jul 6th, 2014
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.28 KB | None | 0 0
  1. #include <stdio.h>
  2. #define TRUE (1)
  3. #define FALSE !TRUE
  4. int sum(int a, int b, int c, int d, int e) {
  5.   int s = a + b + c + d + e;
  6.   if (60 <= s && s <= 100) return TRUE;
  7.   return FALSE;
  8. }
  9. int even(int a, int b, int c, int d, int e) {
  10.   int r = (a % 2 == 0) + (b % 2 == 0) + (c % 2 == 0) + (d % 2 == 0) + (e % 2 == 0);
  11.   if (r == 2 || r == 3) return TRUE;
  12.   return FALSE;
  13. }
  14. int small(int a, int b, int c, int d, int e) {
  15.   int s = (a < 16) + (b < 16) + (c < 16) + (d < 16) + (e < 16);
  16.   if (s == 2 || s == 3) return TRUE;
  17.   return FALSE;
  18. }
  19. int main(void) {
  20.   int a[] = { 1 };
  21.   int b[] = { 5, 3, 16, 28, 4, 9 };
  22.   int c[] = { 14, 3, 15, 21, 31, 27 };
  23.   int d[] = { 7, 10, 22, 23, 30, 24 };
  24.   int e[] = { 12, 8, 18, 25, 19, 20, 9 };
  25.   int *a0, *b0, *c0, *d0, *e0;
  26.   for (a0 = a; a0 < a + sizeof(a) / sizeof(int); a0++)
  27.     for (b0 = b; b0 < b + sizeof(b) / sizeof(int); b0++)
  28.       for (c0 = c; c0 < c + sizeof(c) / sizeof(int); c0++)
  29.         for (d0 = d; d0 < d + sizeof(d) / sizeof(int); d0++)
  30.           for (e0 = e; e0 < e + sizeof(e) / sizeof(int); e0++)
  31.             if (sum(*a0, *b0, *c0, *d0, *e0) && even(*a0, *b0, *c0, *d0, *e0) &&
  32.                 small(*a0, *b0, *c0, *d0, *e0))
  33.               printf("%2d %2d %2d %2d %2d\n", *a0, *b0, *c0, *d0, *e0);
  34.   return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement