#include
void main()
{
float rich=0, stranger;
int i;
for(i=0;i<30;i++) {
rich += 100000.00;
if(i==0)
stranger = 0.01;
else
stranger *= 2;
}
printf ("\n30天后陌生人给了富翁%.0f元,富翁给了陌生人%.0f元.\n", rich, stranger);
}
#include
double SumMoneyInDays(double nBase,int nMultBy,int nDays);
int main()
{
double nMoneyToStranger, nMoneyToMillionaire ;
nMoneyToStranger = SumMoneyInDays(0.01, 2, 30);//陌生人拿到的
nMoneyToMillionaire =10*10000.0f*30; //百万富翁拿到的
printf("陌生人拿到的=%0.2f, 百万富翁拿到的=%0.2f\r\n",nMoneyToStranger, nMoneyToMillionaire);
return 0;
}
double SumMoneyInDays(double nBase,int nMultBy,int nDays)
{
double nRetVal = 0;
int i,j;
double nMoneyToday;
for(i=0;i
nMoneyToday = (0==i)? nBase : nMoneyToday*nMultBy;
nRetVal+=nMoneyToday;
}
return nRetVal;
}
结果:
大富翁得到300万;陌生人得到约1073.74万
======================================
LZ,做人要厚道。以后不要再把一个问题改为四个问题。