SHARE
TWEET

Untitled

a guest Dec 16th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. using namespace std;
  4.  
  5. int sum(int n, ...)
  6. {
  7.     int *p = &n;
  8.     int sign = 1;
  9.     int temp, sum = 0;
  10.     while(*p)
  11.     {
  12.         temp = sign * (*p) * (*++p);
  13.         sum+=temp;
  14.         sign=-sign;ишт
  15.     }
  16.     return sum;
  17. }
  18.  
  19. int main()
  20. {
  21.     int s1 = sum(2, 1, 2, 3, 1, 0);
  22.     int s2 = sum(1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 0);
  23.     int s3 = sum(1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 5, 4, 3, 2, 1, 0);
  24.     printf("s1=%d, s2=%d, s3=%d", s1, s2, s3);
  25.     return 0;
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top