nave@lemmy.zip to Lemmy Shitpost@lemmy.worldEnglish · 1 year agoI wishi.imgur.comimagemessage-square183fedilinkarrow-up1923arrow-down117
arrow-up1906arrow-down1imageI wishi.imgur.comnave@lemmy.zip to Lemmy Shitpost@lemmy.worldEnglish · 1 year agomessage-square183fedilink
minus-squarejsdz@lemmy.mllinkfedilinkInterlinguaarrow-up13·edit-21 year agoint is_even(int n) { int result = -1; char number[8]; //should be enough sprintf(number, "%d", n); // check the number // TODO: handle negative numbers for (char *p=number; *p; p++) { if (*p=='0' || *p=='2' || *p=='4' || *p=='6' || *p=='8') result = 1; else if (*p=='1' || *p=='3' || *p=='5' || *p=='7' || *p=='9') result = 0; else { fprintf(stderr, "Your number is wrong!\n"); exit(1); } } return result; }
minus-squareMolochAlter@lemmy.worldlinkfedilinkarrow-up2arrow-down2·1 year agoThis one is more readable.
This should be the accepted answer
Why not one with modulus?
This one is more readable.