Answer to Question #172811 in C++ for Tripletunes

Question #172811

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.


1
Expert's answer
2021-03-18T03:31:51-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS