当前位置:网站首页>习题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;
}
边栏推荐
- Learning bit segment (1)
- Regular execution of shell scripts in crontab
- Top - K problem
- inner join执行计划变了
- win11怎么看电脑显卡信息
- 二叉树的基本操作与题型总结
- [Yu Yue education] basic engineering English of Zhejiang industrial and Commercial University (wuyiping) reference materials
- 【解决】修改子物体Transform信息导致变换不对称、异常问题的解决方案
- [JS] 1347- high level usage of localstorage
- Stack栈的实现
猜你喜欢

How to view the installation date of the win system

One question per day -- verifying palindrome string

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

二叉树的基本操作与题型总结

C language to achieve eight sorts (2)

win10字体模糊怎么调节

Matplotlib和tkinter学习笔记(一)

leetcode 中的位运算

【学术相关】申请审核制下,到双一流大学读博的难度有多大?

Huawei equipment configuration hovpn
随机推荐
大学三年应该这样过
Unity中使用调用Shell的命令行
C language implements eight sorts (1)
Summary of common paging methods
Study notes of mattlotlib and Tkinter (I)
Basic operation and question type summary of linked list
[today in history] June 11: the co inventor of Monte Carlo method was born; Google launched Google Earth; Google acquires waze
3.3 测试模块的命名规则
如果重来一次高考,我要好好学数学!
Internet of things development practice 18 scenario linkage: how does an intelligent light perceive light? (I) (learning notes)
R7-1 列表或元组的数字元素求和
How to view the installation date of the win system
swiper——单页面多轮播插件冲突解决方案
完好性简要介绍
常用分页方法总结
Unity3D getLaunchIntentForPackage 获取包返回null问题
带有 ceph-csi 的静态 PVC
A simple example of linear regression in machine learning
机器学习之线性回归简单实例
判断链表是否为回文结构