当前位置:网站首页>Exercise 6-2 using functions to sum special A-string sequences
Exercise 6-2 using functions to sum special A-string sequences
2022-07-03 14:09:00 【ᯤ⁹ᴳ⁺ ·】
exercises 6-2 Using functions to find special a A string of numbers and (20 branch )
Given that neither is more than 9 The positive integer a and n, Ask to write a function to find a+aa+aaa++⋯+aa⋯a(n individual a) The sum of the .
Function interface definition :
int fn( int a, int n );
int SumA( int a, int n );
The function fn What has to be returned is n individual a The numbers that make up ;SumA Return the requested and .
Sample referee test procedure :
#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;
}
/* Your code will be embedded here */
sample input :
2 3
sample output :
fn(2, 3) = 222
s = 246int fn( int a, int n ){
int i,r=a;
for(i=0;i<n-1;i++){
a=(a*10)+r;
}
return a;
}
int SumA( int a, int n ){
int i,sum=0;
for(i=1;i<=n;i++){
sum+=fn(a,i);
}
return sum;
}

边栏推荐
- Simulated access
- Duet date picker (time plug-in that can manually enter the date)
- GoLand 2021.2 configure go (go1.17.6)
- 玖逸云黑免费无加密版本源码
- How to promote the progress of project collaboration | community essay solicitation
- Use and design of Muduo buffer class
- Thrift threadmanager and three monitors
- C language standard IO function sorting
- Solve MySQL 1045 access denied for user 'root' @ 'localhost' (using password: yes)
- Depth and breadth first traversal of tree (regardless of binary tree)
猜你喜欢

allegro,orcad, net alias,port,off-page connector之间的异同点和如何选取

FPGA测试方法以Mentor工具为例

GoLand 2021.1: rename the go project

jvm-对象生命周期

Installation impression notes

JVM系列——概述,程序计数器day1-1

Go: send the get request and parse the return JSON (go1.16.4)

JS input number and standard digit number are compared. The problem of adding 0 to 0
[email protected])|制备路线"/>叶酸修饰的金属-有机骨架(ZIF-8)载黄芩苷|金属有机骨架复合磁性材料([email protected])|制备路线

Redis: commandes d'action pour les données de type chaîne
随机推荐
Installation impression notes
Article content typesetting and code highlighting
金属有机骨架MOFs装载非甾体类抗炎药物|ZIF-8包裹普鲁士蓝负载槲皮素(制备方法)
全局事件总线
MySQL 数据处理值增删改
JVM family - overview, program counter day1-1
Redis:字符串類型數據的操作命令
Global event bus
Qt学习24 布局管理器(三)
Rasp implementation of PHP
[acnoi2022] guess numbers
Implementation of Muduo accept connection, disconnection and sending data
selenium 浏览器(1)
Qt学习20 Qt 中的标准对话框(中)
JS continues to explore...
消息订阅与发布
Invalid Z-index problem
战略、战术(和 OKR)
Uniapp tips - set background music
How to bold text in AI