Write a program to find the count of unique digits in a given number N. The number will be passed to the program as the input of type int.
Assumption: The input number will be a positive integer number>=1 and <= 25000.
For e.g.
If the given number is 292, the program should print 2 because there are only 2 unique digits "2" and "9" int this number.
#include <iostream>
using namespace std;
int countUnique(int input)
{
int u = 0;
int store = 0;
int digit = 0;
while(input > 0) {
digit = 1 << (input % 10);
if(!(store & digit)) {
store |= digit;
u++;
}
input /= 10;
}
return u;
}
int main()
{
int n;
cout<<"please enter the number"<<endl;
cin>>n;
cout << countUnique(n);
return 0;
}
Comments
Leave a comment