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