Number of n-digit integers#8817

Number of n-digit integers (Editorial)

There are 9 single-digit numbers: from 1 to 9.

There are 90 two-digit numbers: from 10 to 99.

There are 900 three-digit numbers: from 100 to 999.

The number of -digit natural numbers equals . At n = 10, the answer equals 9 \times 10^9, for which the data type long long should be used.

Implementation of the algorithm

Read the input value .

scanf("%d", &n);

Calculate the answer in the variable res, equal to 9 \times 10^{n-1}.

res = 9;
for (i = 1; i < n; i++)
    res *= 10;

Output the answer.

printf("%lld\n", res);