|
发表于 2013-3-24 19:39:35
|
显示全部楼层
- /*
- 跪求编写以下这个程序,有注解最好,谢谢!购房从银行贷了一笔款d,准备每月还款额为p,月利率为r,
- 计算多少月能还的清。
- 设d=300000元,p=6000元,r为1%。对求得的月份取小数点后一位,对第2位按四舍五入处理。计算公式为:
- m=(logp-log(p-dxr))/log(1+r)
- */
- #include <stdio.h>
- #include <math.h>
- #include <assert.h>
- //根据公式计算
- double how_many_month( double toatal_owned, double pay_per_mobth, double month_rate );
- //取小数点后一位,对第2位按四舍五入处理。
- double deal_result( double month );
- //显示
- void display( double month );
- int main() {
- double month = how_many_month( 300000, 6000, 0.01 );
- month = deal_result( month );
- display( month );
- }
- double how_many_month( double toatal_owned, double pay_per_mobth, double month_rate ) {
- return (log10( pay_per_mobth ) - log10( pay_per_mobth - toatal_owned*month_rate ))/log10( 1+month_rate ) ;
- }
- double deal_result( double month ) {
- assert( month>0 );
- return (int)((month * 10) + 0.5)/10.0;
- }
- void display( double month ) {
- printf( "%.1lf\n",month );
- }
复制代码 |
|