Advertisement
mustahidhasan

sum of even minus odds

Feb 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.38 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5.  
  6.  
  7.  
  8.     int i, n, sum = 0, substract = 0;
  9.     scanf("%d", &n);
  10.  
  11.     for(i = 1; i <= n; i++)
  12.     {
  13.         if(i % 2 == 0)
  14.         {
  15.             sum = sum + i;
  16.         }
  17.         else
  18.         {
  19.            substract = sum - i;
  20.         }
  21.     }
  22.     printf("Sum = %d\n", sum);
  23.     printf("Substract = %d\n", substract);
  24.  
  25.  
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement