write a program to check whether it is unique number or not using while loop only
Answers
Answered by
1
Answer:
void printUnique(int l, int r)
{
// Start traversing the numbers
for (int i=l ; i<=r ; i++)
{
int num = i;
bool visited[10] = {false};
// Find digits and maintain its hash
while (num)
{
// if a digit occcurs more than 1 time
// then break
if (visited[num % 10])
break;
visited[num%10] = true;
num = num/10;
}
// num will be 0 only when above loop
// doesn't get break that means the
// number is unique so print it.
if (num == 0)
cout << i << " ";
}
}
Similar questions
Math,
6 months ago
Computer Science,
6 months ago
Math,
6 months ago
Biology,
1 year ago
Math,
1 year ago
Social Sciences,
1 year ago
Social Sciences,
1 year ago