当前位置:网站首页>递归案列-c
递归案列-c
2022-07-19 05:23:00 【小唐博客】
这是一个存代码
/* 有这样一个场景: 已知第五个同学比第四个同学大两岁,第四个同学 比第三个同学大两岁,第三个同学比第二个同学大 两岁。以此类推,只知道第一个同学10岁,请用 递归的方式表达出这个函数。 */
#include <stdio.h>
int getage(int currPersonNum)
{
int age;
if(currPersonNum==1){
age=10;
}else{
age=getage(currPersonNum-1)+2;
}
return age;
}
int main()
{
int age;
int num;
printf("你想知道第几个学生的年龄:\n");
scanf("%d",&num);
age=getage(num);
printf("第%d的学生的年龄是%d\n",num,age);
return 0;
}
运行程序
D:\C语言\code\第五章函数>gcc demo_exdigui.c
D:\C语言\code\第五章函数>a.exe
你想知道第几个学生的年龄:
32
第32的学生的年龄是72
边栏推荐
- . Net framework introduction
- Reference for Ruijie Switch Configuration
- pytorch梯度的计算过程
- Win10 + cuda11.7+pytorch manual installation -2.0 version
- 探索一下自增自减运算符的使用方式
- .NET Framework简介
- 总结1-深度学习-基础知识学习
- Model in pytorch train(),model. Eval () and torch no_ The difference between grad()
- JVM之GC调优原理(八)
- huawei link agg and port mirroring
猜你喜欢
随机推荐
firewall-cmd
DOM与事件
Unable to get browser (Selenium::WebDriver::Error::NoSuchWindowError)
MariaDB Tutorial
3DSlicer导入锥束CT图像
(2) Detailed examples of practical application of swagger
Kubernetes技术与架构(一)
Kubernetes命令行管理工具 — Kubectl
浮动效果与特点
Solr search engine - solrcloud installation and cluster configuration
几种连接查询的细节讲解
逻辑运算符短路与和短路或的短路作用
XPath filters other tags in the tag to get all the content
pytorch梯度的计算过程
Data type conversion
畅玩树莓派4B(一)树莓派系统安装和SSH连接
FPGA之简易电压表设计
基于若依框架搭建商业项目
Alibaba cloud micro message queue mqtt
数据类型转换