码迷,mamicode.com
首页 > 其他好文 > 详细

循环-16. 猴子吃桃问题

时间:2014-08-02 12:31:03      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   strong   io   for   2014   

 1 /*
 2  * Main.c
 3  * C16-循环-16. 猴子吃桃问题
 4  *  Created on: 2014年8月2日
 5  *      Author: Boomkeeper
 6  *********测试通过********
 7  */
 8 
 9 #include <stdio.h>
10 /*
11  * 根据天数N计算桃子数量
12  */
13 int monkeyEatPeach(int N) {
14 
15     int i, sum = 1;
16 
17     for (i = 2; i <= N; i++) {
18         sum = (sum + 1) * 2;
19     }
20 
21     return sum;
22 }
23 
24 int main(void) {
25 
26     int N; //题目中的N,天数
27 
28     scanf("%d", &N);
29     printf("%d\n", monkeyEatPeach(N));
30 
31     return 0;
32 }

题目链接:

http://pat.zju.edu.cn/contests/basic-programming/%E5%BE%AA%E7%8E%AF-16

 

 

    

循环-16. 猴子吃桃问题,布布扣,bubuko.com

循环-16. 猴子吃桃问题

标签:style   blog   http   color   strong   io   for   2014   

原文地址:http://www.cnblogs.com/boomkeeper/p/C16.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!