yuki给的是三种循环都用到的
。楼主,yuki给的算法看得懂么?


土冒
[此贴子已经被作者于2005-4-24 18:32:23编辑过]
//每个苹果0.8元,第一天买2个苹果,第二天开始,每天买前一天的2倍, //直到购买的苹果数达到不超过100个的最大值。编写程序求每天平均花多少钱。
#include <stdio.h>
void average();
void average() { int counter=0; int day=0; int apple=2; float money; float average; do { day++; counter=counter+apple; apple=2*apple; }while(counter<=100); counter=counter-apple/2; day--; money=counter*0.8; average=money/day; printf("the average menoy is : %f\n",average); } //我也写了一个小程序,可以满足你的要求,看看把