Hello I’m new on this forum and I need help.
I ant to search in a string that was number’s for a number tat is odd.
Example:
String : ( 234) I ant to fin the odd number in that string.
you can make use of fact that the ASCII character code for '0' is 30 decimal, '1' is 31 decimal, '2' is 32 decimal, '3' is 33 decimal, etc. i.e. even numbers have an even character code odd numbers have odd character code
code to test if the character ch was an even or odd number would be
-
char ch='5';
-
if (ch % 2) printf("%c is odd \n",ch);
-
else printf("%c is even \n",ch);
-
% is the modulus (remainder) operator so
ch % 2 gives 0 if ch is even, 1 if ch is odd