How do I do arithmetic operations between a character and a digit in C without using the ascii code

Viewed 78

I want to add the character ‘4’ and the digit 3 and have it equal 7 without any library methods if possible I.e ‘4’ + 3 = 7

1 Answers

For all single digits you can do like:

char c = '4';

// If you want to add 3 now you can do like:
int result = c - '0' + 3;

Subtracting '0' is the key here. That's it

Related