| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 552 人关注过本帖
标题:程序,我们需要多少年买的房
只看楼主 加入收藏
都督
Rank: 1
等 级:新手上路
帖 子:56
专家分:0
注 册:2007-9-12
收藏
 问题点数:0 回复次数:8 
程序,我们需要多少年买的房
有个问题是
假如2015年房价80万,今年我大学毕业第一年月工资是2000元,我的年工资增长率应该至少是多少,到2015年才能买的起房.
用循坏做呀
我想可以这样吗?
for(i=0;i<=7;i++)
{年工资=年工资*(1+年增长率(求的))
if(年工资<=80万)
{break;}
}
不行该怎么算呀
搜索更多相关主题的帖子: 工资 break 大学 房价 
2007-09-13 12:39
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
得分:0 
you don't need to spend money on

0. food
1. housing
2. clothes
3. travel
4. socializing
5. etc.

?

Just a joke.

I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-09-13 13:03
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
得分:0 

#include <stdio.h>
#include <math.h>

#define HOUSE_PRICE 800000.0
#define YEARS 2015-2007

/**
Your annual salary increase is 39.14%
Press any key to continue . . .
*/

float rate(float firstYearSalary)
{
float x=0.0;

do
{
x+=0.0001; // increase by 0.01%
}
while( firstYearSalary * (pow(1.0+x, YEARS)-1)/x < HOUSE_PRICE);

return x*100;
}


int main()
{
float firstYearSalary=24000.0;

printf("Your annual salary increase is %.2f%%\n", rate(firstYearSalary));

return 0;
}


I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-09-13 13:28
snakeImao
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2007-9-10
收藏
得分:0 

"if(年工资<=80万)"

照你的意思,2015年,这一年内至少要赚80万罗?
那你的年工资增长率不就是 55.01% 吗?

[此贴子已经被作者于2007-9-13 15:19:48编辑过]

2007-09-13 14:50
都督
Rank: 1
等 级:新手上路
帖 子:56
专家分:0
注 册:2007-9-12
收藏
得分:0 
付首付,三十万
2007-09-13 18:28
都督
Rank: 1
等 级:新手上路
帖 子:56
专家分:0
注 册:2007-9-12
收藏
得分:0 

do
{
x+=0.0001; // increase by 0.01%//为什么是0.0001呀,哪里的呀
}
while( firstYearSalary * (pow(1.0+x, YEARS)-1)/x < HOUSE_PRICE);

return x*100;

2007-09-13 18:35
都督
Rank: 1
等 级:新手上路
帖 子:56
专家分:0
注 册:2007-9-12
收藏
得分:0 
哦知道了,是x从0.0001开始增长,直到我的工资>=HOUSE_PRICE;
就能知道是增长率是多少了,你真聪明呀,

[此贴子已经被作者于2007-9-13 18:48:05编辑过]

2007-09-13 18:47
都督
Rank: 1
等 级:新手上路
帖 子:56
专家分:0
注 册:2007-9-12
收藏
得分:0 
pow(1.0+x, YEARS)-1)/x
我认为这里应该是firstYearSalary*(1.0+x)的7次方
为什么你这是开方,能解释一下吗?谢谢
2007-09-13 19:01
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
得分:0 
you need to work out the math.

denote the first year salary by a
then 2nd year salary is a(1+x);
3rd year is a(1+x)^2
...
nth year is a(1+x)^n

form year 1 to year n, you will earn (assume that you don't spend any money on food, clothes, etc)

a + a(1+x) + a(1+x)^2 + ...+ a(1+x)^n = a ((1+x)^(n+1) - 1 ) / x

if the last value >= house price, you own the house.

I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-09-14 16:09
快速回复:程序,我们需要多少年买的房
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014190 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved