第35课第五题

来源:互联网 发布:女装淘宝网店货源 编辑:程序博客网 时间:2024/06/06 08:46
#include <stdio.h>#include <stdlib.h>//第五题, 现在北京有一套房子,价格200万,假设房价每年上涨10%,一个软件工程师每年固定能赚40万。如果他想买这套房子,不贷款,不涨工资,没有其//他收入,每年不吃不喝不消费,那么他需要几年才能攒够钱买这套房子int main( ){    double output=200,income=0;    int year=1,flag=0;    while(flag==0&&year<=100)    {        output*=1.1;        income+=40;        printf("%.2lf %.2lf\n",output,income);        if(income>=output)        {            printf("工程师第%d年可以买得起房子,此时房价为%.2lf万元、他的积蓄为%.2lf万元",year,output,income);            flag=1;            break;        }        year++;    }    if(flag==0)        printf("100岁了还是买不起房子……\n");    return 0;}
//大哥100岁了还是买不起房子,有点惨

0 0