Guest User

Untitled

a guest
Oct 23rd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <stdlib.h> /* atoi */
  2. #include <stdio.h> /* printf, scanf */
  3.  
  4. int main(int argc, char* argv[])
  5. {
  6. int len, i, *buf, acc;
  7. if (argc != 2) {
  8. printf("usage: <array length>\n");
  9. return 1;
  10. }
  11. len = atoi(argv[1]);
  12. if (len == 0 || len % 2 == 0) {
  13. printf("bad length\n");
  14. return 1;
  15. }
  16. buf = malloc(len * sizeof(int));
  17. for (i = 0; i < len; i++) {
  18. printf("%d> ", i + 1);
  19. scanf("%d", &buf[i]);
  20. }
  21. acc = 0;
  22. for (i = 0; i < len; i++) {
  23. acc ^= buf[i];
  24. }
  25. printf("result: %d\n", acc);
  26. return 0;
  27. }
Add Comment
Please, Sign In to add comment