pascal题目:【C语言训练】求s=a+aa+aaa+aaaa+aa...a的值

2024-12-23 00:18:06
推荐回答(2个)
回答1:

var
a, n, i, j: Integer;
s: Int64;
begin
Readln(a, n);
s := 0;
if (a <= 9) and (n <= 14) and (n >= 1) then
begin
j := a;
s := j;
for i := 2 to n do
begin
j := j * 10 + a;
Inc(s, j);
end;
end;
Writeln(s);
Readln;
end.

回答2:

可以用数学公式直接表达为:
s=a*(10^(n+1)-9*n-10)/81;