jsdz, (edited )

<span style="color:#323232;">int is_even(int n)
</span><span style="color:#323232;">{
</span><span style="color:#323232;">    int result = -1;
</span><span style="color:#323232;">    char number[8]; //should be enough
</span><span style="color:#323232;">    sprintf(number, "%d", n);
</span><span style="color:#323232;">
</span><span style="color:#323232;">    // check the number
</span><span style="color:#323232;">    // TODO: handle negative numbers
</span><span style="color:#323232;">    for (char *p=number; *p; p++)
</span><span style="color:#323232;">    {
</span><span style="color:#323232;">        if (*p=='0' || *p=='2' || *p=='4' || *p=='6' || *p=='8')
</span><span style="color:#323232;">            result = 1;
</span><span style="color:#323232;">        else if (*p=='1' || *p=='3' || *p=='5' || *p=='7' || *p=='9')
</span><span style="color:#323232;">            result = 0;
</span><span style="color:#323232;">        else {
</span><span style="color:#323232;">           fprintf(stderr, "Your number is wrong!n");
</span><span style="color:#323232;">           exit(1); 
</span><span style="color:#323232;">        }
</span><span style="color:#323232;">    }
</span><span style="color:#323232;">    return result;
</span><span style="color:#323232;">}
</span>
  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • uselessserver093
  • Food
  • aaaaaaacccccccce
  • [email protected]
  • test
  • CafeMeta
  • testmag
  • MUD
  • RhythmGameZone
  • RSS
  • dabs
  • Socialism
  • KbinCafe
  • TheResearchGuardian
  • oklahoma
  • feritale
  • SuperSentai
  • KamenRider
  • All magazines