Skip to content

CoreTask#3: CountDigits - Submit Your Code in Comment Section #28

@ErSKS

Description

@ErSKS

CoreTask#3: CountDigits - Write a function named countDigit that returns the number of times that a given digit appears in a positive number. For example countDigit(32121, 1) would return 2 because there are two 1s in 32121. Other examples: countDigit(33331, 3) returns 4 countDigit(33331, 6) returns 0 countDigit(3, 3) returns 1 The function should return -1 if either argument is negative, so countDigit(-543, 3) returns -1. The function signature is int ountDigit(int n, int digit) Hint: Use modulo base 10 and integer arithmetic to isolate the digits of the number.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions