当前位置:网站首页>Exercise 6-2 using functions to sum a special series of a numbers (20 points)
Exercise 6-2 using functions to sum a special series of a numbers (20 points)
2022-06-11 22:25:00 【Xiaoyan y】
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 = 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;
}
边栏推荐
- [Chongqing Guangdong education] college physics of Xiangtan University: mechanical and thermal reference materials
- 点云读写(二):读写txt点云(空格分隔 | 逗号分隔)
- Superscalar processor design yaoyongbin Chapter 2 cache -- Excerpt from subsection 2.3
- 什么是死锁?(把死锁给大家讲明白,知道是什么,为什么用,怎么用)
- 論文閱讀《Dense Visual SLAM for RGB-D Cameras》
- Tkinter学习笔记(三)
- 一款开源的Markdown转富文本编辑器的实现原理剖析
- NLP - fastText
- Two methods to judge the storage of large and small end
- STM32 development note 113:ads1258 drive design - reading temperature value
猜你喜欢

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

What is deadlock? (explain the deadlock to everyone and know what it is, why it is used and how to use it)

Tkinter study notes (IV)

【数据挖掘时间序列分析】餐厅销量预测

The device is in use when win10 ejects USB

Two methods to judge the storage of large and small end

Study notes of mattlotlib and Tkinter (I)

什么是死锁?(把死锁给大家讲明白,知道是什么,为什么用,怎么用)

MySQL事务简介

Bit operation in leetcode
随机推荐
Explain asynchronous tasks in detail: the task of function calculation triggers de duplication
Introduction to MySQL transactions
Inner join execution plan changed
Bit operation in leetcode
STM32 Development Notes 112:ads1258 driver design - read register
Use the securecrtportable script function to read data from network devices
Is it safe for qiniu business school to send Huatai account? Really?
习题8-2 在数组中查找指定元素 (15 分)
[nodejs] electron installation
Learning bit segment (1)
If I take the college entrance examination again, I will study mathematics well!
NLP - fastText
Precision twist jitter
[Yu Yue education] basic engineering English of Zhejiang industrial and Commercial University (wuyiping) reference materials
[Yu Yue education] Yancheng Normal University Advanced Algebra reference
Tkinter学习笔记(三)
MATLAB点云处理(二十四):点云中值滤波(pcmedian)
C language to achieve eight sorts (2)
重温c语言一
238. product of arrays other than itself