urgent

please if i want to enter like 27 and want to count how many numbers from 0 to 27 except the like number e.g. 11 , 22 , etc.
can any one help me in write this
Is the input limited to the numbers 0-99?

How can you programmatically determine if the tens digit equals the ones digit?
no limited till 10,000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
bool areAllDigitsEquals(int number)
{
    std::stringstream ss;
    ss << number;
    std::string str = ss.str();
    if (str.size() <= 1)
    {
        return false;
    }
    int prev = str[0];
    for(size_t i = 1, count = str.size(); i < count; ++i)
    {
        if (prev != str[i])
        {
            return false;
        }
        prev = str[i];
    }
    return true;
}
Last edited on
i need help again
i need the parameter of the problem as this
int count(int n)
closed account (jLNv0pDG)
1
2
3
4
5
6
7
int count(int n) {
	int total = n;
	for(int i = 0; i <= n; ++i) {
		total -= areAllDigitsEquals(i);
	};
	return total;
}


You can just need a for loop to keep calling Denis' code.
Last edited on
Supposing that the input is limited to 2 digits, I will add to jsmith's questions (hints).

For a number n, what is n / 10?
For a number n, what is n % 10?
@moorecm, I would have posted the same if not for:
no limited till 10,000

makes it a bit harder if the size is anywhere between 0 and that using modulo
Last edited on
Topic archived. No new replies allowed.