代码实现如下:
#include <stdio.h>
int main(int argc, const char *argv[])
{
int duck = 2, n;
int s;
for(n = 7; n > 0; n--)
{
duck = (duck + 1) * 2;
}
printf("出发时共赶%d只鸭子\n", duck);
for(n = 1; n <= 7; n++)
{
s = duck / 2 + 1;
printf("经过第%d个村子卖出%d只鸭子\n", n, s);
duck = duck - s;
}
return 0;
}
运行结果: