当前位置:网站首页>习题6-2 使用函数求特殊a串数列和 (20 分)
习题6-2 使用函数求特殊a串数列和 (20 分)
2022-06-11 22:19:00 【小言同学Y】
给定两个均不超过9的正整数a和n,要求编写函数求a+aa+aaa++⋯+aa⋯a(n个a)之和。
函数接口定义:
int fn( int a, int n );
int SumA( int a, int n );
其中函数fn须返回的是n个a组成的数字;SumA返回要求的和。
裁判测试程序样例:
#include <stdio.h>
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;
}/* 你的代码将被嵌在这里 */
输入样例:
2 3
输出样例:
fn(2, 3) = 222
s = 246
int fn( int a, int n ){
int i,sum=0;
for(i=0;i<n;i++){
sum+=a;
a*=10;
}
return sum;
}
int SumA( int a, int n ){
int i,count=0;
for(i=1;i<=n;i++){
count+=fn(a,i);
}
return count;
}
边栏推荐
- 5.学城项目 支付宝支付
- Implementation of stack stack
- Go OS module
- 3.2 naming rules of test classes
- [nodejs] electron installation
- 打印机无法打印测试页是什么原因
- Analysis of the implementation principle of an open source markdown to rich text editor
- Unity3d getlaunchintintforpackage getting package returned null
- The college entrance examination is over, and life has just begun. Suggestions from a 10-year veteran in the workplace
- Tkinter study notes (III)
猜你喜欢

crontab中定时执行shell脚本

电脑强制关机 oracle登录不上

Leetcode - day 2

Collection of articles and literatures related to R language (continuously updated)
![[Chongqing Guangdong education] college physics of Xiangtan University: mechanical and thermal reference materials](/img/64/683a190d14406a9971edd79037cc97.jpg)
[Chongqing Guangdong education] college physics of Xiangtan University: mechanical and thermal reference materials

Tkinter study notes (II)

Inner join execution plan changed

If I take the college entrance examination again, I will study mathematics well!

如果重来一次高考,我要好好学数学!

R language book learning 03 "in simple terms R language data analysis" - Chapter 10 association rules Chapter 11 random forest
随机推荐
Explain asynchronous tasks in detail: the task of function calculation triggers de duplication
R language book learning 03 "in simple terms R language data analysis" - Chapter 8 logistic regression model Chapter 9 clustering model
Is the securities account recommended by qiniu safe? Is it reliable
[Yu Yue education] General English of Shenyang Institute of Engineering (4) reference materials
R language book learning 03 "in simple terms R language data analysis" - Chapter 10 association rules Chapter 11 random forest
Analysis of the implementation principle of an open source markdown to rich text editor
What is deadlock? (explain the deadlock to everyone and know what it is, why it is used and how to use it)
Collection of articles and literatures related to R language (continuously updated)
MATLAB点云处理(二十五):点云生成 DEM(pc2dem)
SVN本地部署server和cleint 并用阿里云盘自动备份
玩家必读|Starfish NFT进阶攻略
206. reverse linked list
win11怎么看电脑显卡信息
如果重来一次高考,我要好好学数学!
Two methods to judge the storage of large and small end
3.2 测试类的命名规则
Go OS module
完好性简要介绍
STM32 Development Notes 112:ads1258 driver design - read register
Dynamic memory management (1)