Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h> /* atoi */
- #include <stdio.h> /* printf, scanf */
- int main(int argc, char* argv[])
- {
- int len, i, *buf, acc;
- if (argc != 2) {
- printf("usage: <array length>\n");
- return 1;
- }
- len = atoi(argv[1]);
- if (len == 0 || len % 2 == 0) {
- printf("bad length\n");
- return 1;
- }
- buf = malloc(len * sizeof(int));
- for (i = 0; i < len; i++) {
- printf("%d> ", i + 1);
- scanf("%d", &buf[i]);
- }
- acc = 0;
- for (i = 0; i < len; i++) {
- acc ^= buf[i];
- }
- printf("result: %d\n", acc);
- return 0;
- }
Add Comment
Please, Sign In to add comment