导航:首页 > 编程语言 > 猴子吃桃问题编程

猴子吃桃问题编程

发布时间:2025-06-28 07:02:36

㈠ 猴子吃桃问题(3种方法实现)

/*猴子吃桃*/
#include "malloc.h"
int day[10]; //每天的桃数
struct d{
int tao; //桃
struct d *yesterday; //昨天的指针
}today;
int all;

int Fun1()
{
int i;
day[9]=1;
for(i=8;i>-1;i--) //从最后一天算起
{
day[i]=(day[i+1]+1)*2;
}
printf("%d\n",day[0]); //输出第一天的
}
int Fun2()
{
int i;
int tot;
struct d *p;
today.tao=1;
p=&today; //先到最后一天
i=1;

while(i<10)
{
tot=p->tao; //保存当前天的桃
p->yesterday=malloc(sizeof(struct d)); //分配空间,并当前天的前一天指向该地址
p=p->yesterday; //当前天变为前一天
p->tao=(tot+1)*2; //计算
i++;} //下一天
printf("%d\n",p->tao); //输出

}

int Fun3(d)
int d;
{
if(d==1) return 1; //递归出口
else return (Fun3(d-1)+1)*2; //计算
}

int main()
{
Fun1();
Fun2();
all=Fun3(10);
printf("%d",all);
getchar();
}

编程,猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不过瘾,又多吃了一个。第2天早上将

int day, x1, x2;
day = 9;
x2 = 1;
while (day > 0)
{
x1 = (x2 + 1) * 2; /*第一天的桃子是第二天桃子数加1后的2倍*/
x2 = x1;
day--; /*因为从后向前推所以天数递减*/
Console.WriteLine("the total is {0}", x1);
Console.ReadKey();

阅读全文

与猴子吃桃问题编程相关的资料

热点内容
思科交换机的命令 浏览:152
tiffpdf 浏览:556
邮储银行app怎么转村镇银行 浏览:893
710服务器怎么进入PE 浏览:483
编译原理论文标题 浏览:840
人权pdf 浏览:114
10m阿里云服务器 浏览:75
单片机ad数据 浏览:763
php判断用户是否在线 浏览:475
怎么轻功比app的历史记录 浏览:420
1g2m云服务器推荐 浏览:253
python标准库下载 浏览:949
4a怎么把app移到内存卡 浏览:598
白夜极光怎么换服务器 浏览:829
pb反编译软件购买 浏览:811
不会失业的职业是程序员和白领 浏览:625
将编译库文件写入配置文件 浏览:872
安卓如何下载插件 浏览:796
jqueryajax登录php 浏览:211
php时间变量类型 浏览:312