在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 婆婆高寿祝福语大全简短