Write a function Unique_Occurance and call the function to find the count of unique occurrence 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 1 because there are only 1 unique occurrence digit "9" int this number.
#include <iostream>
using namespace std;
int Unique_Occurance (int input) {
int n = 0, arr[n];
while (input > 0) {
arr[n++] = input % 10;
input /= 10;
}
int countUnique = 0;
int numbers[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
for (int i = 0; i < 10; i++) {
int count = 0;
for (int j = 0; j < n; j++) {
if (numbers[i] == arr[j]) {
count++;
}
}
if (count == 1) {
countUnique++;
}
}
return countUnique;
}
int main () {
int N;
cout << "Enter a positive integer number >= 1 and number <= 25000." << endl;
cin >> N;
cout << "The number of unique numbers in integer is " << Unique_Occurance(N) << endl;
}
Comments
Leave a comment