Write a C++ program to count all the numbers with unique digits within a given range 0 = y < 10n where y represent the unique digits numbers and take n as a input from the user
- برمجة سي بلس بلس
- برمجة
- 2021-05-13
- MarwaMohammed
الأجوبة
#include <iostream>
#include <cmath>
using namespace std;
int count_Unique_Digits_numbers(int n) {
if (n == 0) {
return 1;
}
int ctr = 10;
for (int k = 2, fk = 9; k <= n; ++k) {
fk *= 10 - (k - 1);
ctr += fk;
}
return ctr;
}
int main()
{
int n = 1;
cout << "\nn = " << n << ", Number of unique digits: " << count_Unique_Digits_numbers(n) << endl;
n = 2;
cout << "\nn = " << n << ", Number of unique digits: " << count_Unique_Digits_numbers(n) << endl;
return 0;
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال