# Answer to Question #62972 in C for LART

Question #62972

ALGORITHM FOR NIM GAME

Expert's answer

#include <stdio.h>

int main() {

int n; //number of stones

scanf("%d", &n);

int i, res = 0;

for (i = 0; i < n; i++) {

int k; //numbers of stones in ith heap

scanf("%d", &k);

//finding xor-sum of sequence

res ^= k;

}

printf("%s won\n", res != 0 ? "First" : "Second");

return 0;

}

int main() {

int n; //number of stones

scanf("%d", &n);

int i, res = 0;

for (i = 0; i < n; i++) {

int k; //numbers of stones in ith heap

scanf("%d", &k);

//finding xor-sum of sequence

res ^= k;

}

printf("%s won\n", res != 0 ? "First" : "Second");

return 0;

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment