Answer to Question #172194 in C++ for Raj

Question #172194

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.


1
Expert's answer
2021-03-18T12:49:16-0400
#include <iostream>


using namespace std;


int main()
{
	int number = 0;
	cout << "Enter number: ";
	cin >> number;
	int a[10];
	for(int i = 0; i < 10; i++)
	{
		a[i] = 0;
	}
	while(number > 0)
	{
		a[number%10]++;
		number /= 10;
	}
	int count = 0;
	for(int i = 0; i < 10; i++)
	{
		if(a[i] > 0) count++;
	}
	cout << "Quantity of unique numbers is: " << count << endl;
	return 0;
}

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