当前位置:网站首页>习题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;
}
边栏推荐
- Implementation of sequencelist sequence table
- How to view the installation date of the win system
- 常用分页方法总结
- 【学术相关】申请审核制下,到双一流大学读博的难度有多大?
- leetcode 257. Binary tree paths all paths to a binary tree (simple)
- 如果重来一次高考,我要好好学数学!
- Addition without addition, subtraction, multiplication, Division
- 每日一题-1317. 将整数转换为两个无零整数的和
- 【Uniapp 原生插件】商米钱箱插件
- Leetcode stack topic summary
猜你喜欢

The device is in use when win10 ejects USB

玩家必读|Starfish NFT进阶攻略

论文阅读《Dense Visual SLAM for RGB-D Cameras》

R language book learning 03 "in simple terms R language data analysis" - Chapter 7 linear regression model

How to view the installation date of the win system

Collection of articles and literatures related to R language (continuously updated)

超標量處理器設計 姚永斌 第2章 Cache --2.4 小節摘錄

astra pro双目相机ros下启动笔记
![[niuke.com] ky41 put apples](/img/55/cc246aed1438fdd245530beb7574f0.jpg)
[niuke.com] ky41 put apples

【LeetCode】11. Container with the most water
随机推荐
STM32 Development Notes 112:ads1258 driver design - read register
超标量处理器设计 姚永斌 第2章 Cache --2.3 小节摘录
Go IO module
[uniapp native plug-in] shangmi cashbox plug-in
带有 ceph-csi 的静态 PVC
926. 将字符串翻转到单调递增
[Yu Yue education] General English of Shenyang Institute of Engineering (4) reference materials
Precision twist jitter
Lecture de l'article dense Visual SLAM for RGB - D Cameras
Matlab: solution of folder locking problem
【LeetCode】11. Container with the most water
Tkinter学习笔记(三)
Players must read starfish NFT advanced introduction
win10字体模糊怎么调节
Learning bit segment (1)
astra pro双目相机ros下启动笔记
启牛商学院送华泰账户安不安全?真的吗
R7-1 列表或元组的数字元素求和
Sword finger offer array question type summary
[today in history] June 11: the co inventor of Monte Carlo method was born; Google launched Google Earth; Google acquires waze