在C ++中以0作为数字计算'd'位正整数
在本教程中,我们将讨论一个程序来查找具有“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
热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短