当前位置:网站首页>C-10 age issues
C-10 age issues
2022-04-22 07:53:00 【Tang Encheng_ hhhc】
Problem B: Age issues
Time Limit: 1 Sec Memory Limit: 64 MB
Submit: 12725 Solved: 8524
Description
Yes n A person sits together , Ask No n How old is an individual ? He said bidi n-1 Personal big m year . Ask No n-1 Personal age , He said bidi n-2 Personal big m year . Ask No n-2 personal , And he said bidi n-3 National People's Congress m year .… Finally, ask the first person , He says it is K year . May I ask n How old are you ? ( Recursive function implementation )
Input
Multiple sets of test data Each group has one row. Input separately 3 It's an integer n, m and k
Output
Output No n Personal age
Sample Input
5 2 10
Sample Output
18
#include <stdio.h>
int age(int n,int m,int k);
int main()
{
int n,m,k;
while (scanf("%d%d%d",&n,&m,&k) != EOF)
{
printf("%d\n",age(n,m,k));
}
return 0;
}
// Recursive conditions : Please n Personal age = n-1 Personal age +m
// Up to recursive condition : The first 1 An individual's age is k year , return k
int age(int n,int m,int k)
{
int sum = 0;
if (n == 1)
return k;
else
sum += age(n-1,m,k) + m;
return sum;
}
Do recursive questions , To find the recursive core expression !
Find the return value or condition up to recursion !
版权声明
本文为[Tang Encheng_ hhhc]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220621320273.html
边栏推荐
- Xshell连接虚拟机
- QT advertising screen (multi display split screen + full screen display picture)
- Crawler 51job
- 解决ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed
- [communication interface can bus]
- RT thread [III] link Detailed explanation of LDS link script
- MQTT[一]基础知识介绍
- unityJson文件创建和读取
- Arduino中一种变通的发送固定格式中文短信的方法:以DHT22+GSM模块为例
- Unity reads Excel data and creates the corresponding JSON file
猜你喜欢
随机推荐
C-11 Problem I: 找气球
进制转换--学习总结
树莓派:4.2寸墨水屏
【从零开始写漏扫】主机发现——手写一个子域名挖掘器
Stm32外设篇 [四] RCC
[C - attribute]
Unity 获取网络 并转换成时间戳
Enumerations and structures in C #
@ transactional transaction propagation in the same class
Use of branches in C #
C-11 Problem H: 开宝箱2
redis监听key过期事件
寻找3d地图上没有障碍物的点
Unity Update当前帧与上一帧鼠标的差值获取
Circular explanation and various small details
Unity gets the network and converts it to a timestamp
C#集合
C-10 年龄问题
Use of method C
Problem C: 用链表实现约瑟夫环







![STM32 peripherals [iv] RCC](/img/e1/e81d1e6017bebc87690227a7aa5f99.png)

