Computer >> 컴퓨터 >  >> 프로그램 작성 >> C++

C++에서 0을 숫자로 사용하여 'd' 숫자 양의 정수 계산

<시간/>

이 튜토리얼에서는 0을 숫자로 사용하여 'd'자리 숫자를 찾는 프로그램에 대해 설명합니다.

이를 위해 숫자 '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