Explanation of Code Challenge #1 Let’s take a 3 digit no. 158 To reverse this digit we need to replace ones digit(8) with hundreds digit (1). We need to divide the integer(158) with 10 to get remainder 8. In computer programming we use %(modulus) operator to calculate the remainder. One’s digit(8) will be obtained by expression 158%10 . Now we need hundred’s digit so for it we will divide 158 by 100. Therefore the expression will be 158/100 and it will give 1. Note: When we didvide an integer by another integer in a programming language like C/C++. It will give only integer value i.e, 158/100 will give 1 (not 1.58) as fractional part is removed. Now we would also need tens’s place. for it we will divide 158 by 100, take remainder and subtract ones place from it. i.e, 158%100-158%10 Now we have obtained 50 as it is. We don’t need to change its’s value as it’s place is not being changed. The reverse digit will be: (158%10)*100+(158%100-158%10)+158/1 [which...
Posts
Showing posts from February, 2018