helppp

How many natural numbers are 2 digit digits different
First think about what are Natural numbers.
They're numbers belonging to 1, 2, 3, ... (I was taught that it doesn't include 0).

Now think about which of the Natural numbers have only 2 digits.
10, 11, 12, ... , 99
That's 90 numbers

Now find the which of these 90 numbers possess the given property i.e, the digits are different.

You could solve this with a pen and paper using permutations but since this is a programming forum, they probably want you to do it iteratively.

So write a for-loop that loops from the numebers 10 to 99.
for (int i = ???; i <= ???; i++) { ... }

Now verify whether 'i' satisfies the given property.
Here's a hint:
If N is a 2 digit number,
N1 = N%10 (that is the remainder from dividing by 10) will give you the one's digit.
N2 = N/10   (that is the quotient from dividing by 10) will give you the ten's digit.


Now write an if condition inside the loop, If true; increment a variable..
1
2
3
if (condition involving i/10 and i%10) {
   increment a variable;
}
There are 90 natural numbers with 2 digits.
Of these, 9 have two equal digits.
So, 90-9 = 81 have different digits.

This is one of those cases where I don't think it makes sense to write a program.
Yeah but it becomes hard to frame problems that are both easy to program and not easily solved by hand. Maybe they could have made it 4 digits rather than 2, but it can still easily be solved by hand using combinatorics. At the end of the day it gets the job done and that's what's important ;)

Unfortunately the OP would have no choice but to do it iteratively.
thank you very much :)
Topic archived. No new replies allowed.