在 C++ 中计数正整数 'd' 位数且包含 0
本教程将讨论如何编写程序,用以查找包含 'd' 位数并以 0 为位数之一的数字。
为此,我们将提供数字 'd'。我们的任务是计数和打印包含 'd' 位数且以 0 为其位数之一的正整数的个数。
示例
#include<bits/stdc++.h>
using namespace std;
//counting the number of 'd' digit numbers
int count_num(int d) {
return 9*(pow(10,d-1) - pow(9,d-1));
}
int main(){
int d = 1;
cout << count_num(d) << endl;
d = 2;
cout << count_num(d) << endl;
d = 4;
cout << count_num(d) << endl;
return 0;
}输出
0 9 2439
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP