2013

求桃子总数

 1 #include <stdio.h>
 2 
 3 int main()
 4 {
 5     int i,n,taozi;
 6     while (scanf_s("%d", &n) != EOF)
 7     {
 8         taozi = 1;
 9         for (i = n - 1; i > 0; i--)
10         {
11             taozi = (taozi + 1)*2;
12         }
13         printf("%d\n",taozi);
14     }
15     return 0;
16 }

参考答案

 1 #include <math.h>
 2 #include <stdio.h>
 3 
 4 int main(void)
 5 {
 6     int n;
 7 
 8     while (scanf("%d", &n) != EOF)
 9         printf("%.0f\n", 3 * pow(2, n - 1) - 2);
10 
11     return 0;
12 }

 

posted @ 2016-03-28 10:30  ailx10  阅读(154)  评论(0编辑  收藏  举报