ในบทช่วยสอนนี้ เราจะพูดถึงโปรแกรมที่หาตัวเลขที่มี 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