How to find position of a digit in a number in C programming?

This program will find out the position of a digit in a number. For example digit 4 is present in 41234253 at 4th and 8th positions from left.
Logic is simple, we start with the number say 41234253 and do modulo operation with 10. We’ll get the last digit 3. If it matches the digit (4 here) we are comparing with then we can say the position is 1. If not we can do same thing with remaining digits from the number (4123425). To get the remaining digits we do integer div operation with 10. In every iteration we’ll increase the position count by 1. Here is the program.

He is the Output:

Leave a Reply

Your email address will not be published. Required fields are marked *