Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main() {
- int number;
- printf("Please Enter the Value of 'n' : \n");
- scanf("%d",&number);
- printf("\nThe sum is: %d\n", getSum(number) );
- return 0;
- }
- int getSum(int n) {
- int sum;
- sum = (n % 2 == 0) ? -(n / 2) : (n + 1) / 2;
- /* if (n%2 == 0)
- then, -(n / 2)
- else, (n+1) / 2
- */
- return sum;
- }
Add Comment
Please, Sign In to add comment