习题6-2 使用函数求特殊a串数列和
作者:互联网
1 #include <stdio.h> 2 3 int fn(int a, int n); 4 int SumA(int a, int n); 5 6 int main() 7 { 8 int a, n; 9 10 scanf_s("%d %d", &a, &n); 11 printf("fn(%d, %d) = %d\n", a, n, fn(a, n)); 12 printf("s = %d\n", SumA(a, n)); 13 14 return 0; 15 } 16 17 /* 你的代码将被嵌在这里 */ 18 int fn(int a, int n) 19 { 20 int number = 0; 21 for (int i = 0; i < n; i++) 22 { 23 number = number * 10 + a; 24 } 25 26 return number; 27 } 28 29 int SumA(int a, int n) 30 { 31 int sum = 0; 32 for (int i = 1; i <= n; i++) 33 { 34 sum = sum + fn(a, i); 35 } 36 37 return sum; 38 }
标签:return,数列,int,number,SumA,printf,习题,fn,函数 来源: https://www.cnblogs.com/2018jason/p/10962150.html