enamsustcse

10783 odd sum

May 1st, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     int a, b, i = 0, n, c, d = 0, sum, temp;
  6.  
  7.     scanf("%d", &n);
  8.  
  9.     while (i < n)
  10.     {
  11.         sum = 0;
  12.  
  13.         scanf("%d %d", &a, &b);
  14.  
  15.         temp = a;
  16.  
  17.         c = a % 2;
  18.  
  19.         while (c == 1)
  20.         {
  21.             sum = sum + temp;
  22.             temp = temp + 2;
  23.  
  24.             if ((temp == (b + 1)) || (temp == (b + 2))) c = 2;
  25.         }
  26.  
  27.         if (c == 0)
  28.         {
  29.             d = 1;
  30.             temp = a + 1;
  31.         }
  32.  
  33.         while (d == 1)
  34.         {
  35.  
  36.             sum = sum + temp;
  37.             temp = temp + 2;
  38.  
  39.             if ((temp == (b + 1)) || (temp == (b + 2))) d = 2;
  40.         }
  41.  
  42.         printf("Case %d: %d\n", i + 1, sum);
  43.  
  44.         i++;
  45.     }
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment