All right.Err, getting the last digit in C is as easy as indexing it to sizeof()-1 ?
Yes, but I needed info on how to do it. QwertyM has replied to that nowI don't think that should be difficult. In PHP, there is a function for this. Since PHP syntax is derived from C, I am sure there must be a similar function in C too.
Ok, here is the PHP code to do it. As I said, there is an inbuilt function to get a substring out from a string.
PHP:<?php $input="12345";//input number $last_digit=substr($input,"-1");//get the last digit if($last_digit=="0" || $last_digit=="2" || $last_digit=="4" || $last_digit=="6" || $last_digit=="8") //compare the last digit to see if its either of 0, 2, 4, 6 or 8, or use in_array() function. { print "Input is an even number"; } else { print "Input is an odd number"; } ?>
Wouldn't using case be better instead of if?
Last edited: