Enter two integers a and n, (1≤n≤ 14, 1≤a≤9), and calculate? a+aa+aaa+ ...
Analysis:
Here, the value of n reaches 14, which is far beyond the range of integers, but not beyond the effective range of double precision data. So you can use double to store the results of n A, and plastic surgery will overflow.
Implementation process:
Define a bivariate da, accumulate the result variable sum, and initialize it to 0.
Two integer variables, A and N, are defined to store input data.
Circularly generate a, aa, aaa and other data, store them in da, and accumulate them? :da = da * 10+a; ? sum+= da;
At the end of the loop, the cumulative result (which looks like an integer) is output with% .0f.
Reference code: