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;
}
|