实验6-3 使用函数求特殊a串数列和 (20分)




http://pta.patest.cn/pta/test/13/exam/3/question/475



#include
#include
int fn( int a, int n );
int SumA( int a, int n );
int main()
{
    int a, n;
    scanf("%d %d", &a, &n);
    printf("fn(%d, %d) = %d\n", a, n, fn(a,n));
    printf("s = %d\n", SumA(a,n));
    return 0;
}
int fn( int a, int n )
{
int sum=0,i,b=1;
for(i=0;i {
//b=b*10;
sum=sum+a*b;
b=b*10;
}
return sum;
}
int SumA( int a, int n )
{
int sum1=0,sum2,i;
for(i=1;i {
sum2=fn(a,i);
sum1=sum1+sum2;

}
return  sum1;


}

你可能感兴趣的:(C语言,C,编程,软件开发,函数)