Count number of odd digits in a number

Beginner Problems Basic Maths Easy
  • This problem showcases the use of modulo operation and string manipulation which are both fundamental concepts in programming
  • In real-world applications, the problem can be related to the processing of user input in apps or software - for example, credit card numbers, phone numbers, or social security numbers
  • Here, each digit may need to be individually checked and processed, either for validation, encryption, or some other kind of transformation
  • In such cases, code similar to the solution of this problem could be used

You are given an integer n. You need to return the number of odd digits present in the number.


The number will have no leading zeroes, except when the number is 0 itself.

Examples:

Input: n = 5

Output: 1

Explanation: 5 is an odd digit.

Input: n = 25

Output: 1

Explanation: The only odd digit in 25 is 5.

Input: n = 15

Constraints

  • 0 <= n <= 5000
  • n will contain no leading zeroes except when it is 0 itself.

Company Tags

TCS Cognizant Accenture Infosys Capgemini Wipro IBM HCL Tech Mahindra MindTree