ในบทช่วยสอนนี้ เราจะพูดถึงโปรแกรมเพื่อค้นหาจำนวนตัวเลข N หลักที่เป็นไปได้ซึ่งตรงตามเงื่อนไขที่กำหนด
สำหรับสิ่งนี้เราจะได้รับจำนวนเต็ม หน้าที่ของเราคือตรวจสอบว่าหมายเลขใดที่มีตัวเลข N ตามด้วย
ตัวเลข + ถอยหลัง (ตัวเลข) =10N -1
ตัวอย่าง
#include <bits/stdc++.h>
using namespace std;
//returning the count of numbers
string count_num(int N){
if (N % 2 == 1)
return 0;
string result = "9";
for (int i = 1; i <= N / 2 - 1; i++)
result += "0";
return result;
}
int main(){
int N = 4;
cout << count_num(N);
return 0;
} ผลลัพธ์
90