第1个回答 2019-12-21
我以前写过一个一样的程序,你可以看一下。
/*this
program
can
calculate
a+aa+aaa+...
...+aaa...aaa(n
a).*/
#include
int
main(void)
{
int
sum
=
0,s
=
0,a,digit,power
=
1,i;
printf("please
input
the
value
of
number
and
digits:");
scanf("%d%*c%d",&a,&digit);
//digit
is
"n"
in
the
expression.
for(i
=
0;i
<
digit;i++)
//loop
"digit"
times.
{
s
+=
power*a;
//s
is
one
item
of
the
expression.
sum
+=
s;
power
*=
10;
}
printf("the
summary
is:%d\n",sum);
return
0;
}