当前位置:网站首页>习题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.学城项目 支付宝支付
- Internet of things development practice 18 scenario linkage: how does an intelligent light perceive light? (I) (learning notes)
- 剑指offer数组题型总结篇
- leetcode 257. Binary tree paths all paths to a binary tree (simple)
- Dynamics 365 选项集操作
- One question of the day - delete duplicates of the ordered array
- Huawei equipment configuration hovpn
- STM32开发笔记112:ADS1258驱动设计——读寄存器
- How to adjust the font blur of win10
- Uncover the secret of the popular app. Why is it so black
猜你喜欢
![[niuke.com] DP30 [template] 01 Backpack](/img/a2/9bcfbe6f78f30282fd8940c57477b1.jpg)
[niuke.com] DP30 [template] 01 Backpack

R language book learning 03 "in simple terms R language data analysis" - Chapter 10 association rules Chapter 11 random forest
![[niuke.com] ky41 put apples](/img/55/cc246aed1438fdd245530beb7574f0.jpg)
[niuke.com] ky41 put apples
![[today in history] June 11: the co inventor of Monte Carlo method was born; Google launched Google Earth; Google acquires waze](/img/eb/147d4aac20639d50b204dcf424c9e2.png)
[today in history] June 11: the co inventor of Monte Carlo method was born; Google launched Google Earth; Google acquires waze

Popular science | what are the types of NFT (Part 1)

Inner join execution plan changed

超标量处理器设计 姚永斌 第2章 Cache --2.2 小节摘录

Tkinter学习笔记(四)

How to view the installation date of the win system

Internet of things development practice 18 scenario linkage: how does an intelligent light perceive light? (I) (learning notes)
随机推荐
3.3 测试模块的命名规则
5.学城项目 支付宝支付
[Yu Yue education] basic engineering English of Zhejiang industrial and Commercial University (wuyiping) reference materials
重温c语言一
Leetcode - day 2
超標量處理器設計 姚永斌 第2章 Cache --2.4 小節摘錄
【Uniapp 原生插件】商米钱箱插件
Go encoding package
win10字体模糊怎么调节
Huawei equipment configuration hovpn
移动端——swipe特效之图片时间轴
Why is the printer unable to print the test page
剑指offer数组题型总结篇
Go OS module
一款开源的Markdown转富文本编辑器的实现原理剖析
Win10弹出USB时出现该设备正在使用的解决方法
Study notes of mattlotlib and Tkinter (I)
Implementation of stack stack
Start notes under the Astro Pro binocular camera ROS
MATLAB点云处理(二十五):点云生成 DEM(pc2dem)