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>
#include <string>
using namespace std;
int main(){
int b;
bool flag = true;
while(flag){
cout<<"Input the number between 1 and 25000.\n";
cin>>b;
flag = true;
if(b >= 1 && b <= 25000)
flag = false;
}
string a = to_string(b);
char unique[a.length()];
int count = 0;
for(int i = 0; i < a.length(); i++){
flag = false;
for(int j = 0; j < i; j++){
if(a[i] == a[j]){
flag = true;
break;
}
}
if(!flag){
count++;
}
}
cout<<count<<" unique digit(s) in "<<b;
return 0;
}
Comments
Leave a comment