怎样存钱利息最大及怎样买房付款最省钱问题

假设银行整存整取存款不同期限的月息利率分别为:

0.63% 期限=1年

0.66% 期限=2年

0.69% 期限=3年

0.75% 期限=5年

0.84% 期限=8年

利息=本金*月息利率*12*存款年限。

现在某人手中有2000元钱,请通过计算选择一种存钱方案,使得钱存入银行20年后得到的利息最多(假定银行对超过存款期限的那一部分时间不付利息)。

#include<stdio.h>

#include<math.h>

void makeMoremoney()

{

    int i,j,k,m,n,a,b,c,d,e;

    double r1=0.0063;

    double r2=0.0066;

    double r3=0.0069;

    double r4=0.0075;

    double r5=0.0084;

    double max=0.00,temp;

    for(i=0;i<=20;i++)

    {

        for(j=0;j<=20/2;j++)

        {

            for(k=0;k<=20/3;k++)

            {

                for(m=0;m<=20/5;m++)

                {

                    for(n=0;n<=20/8;n++)

                    {

                     if(i+2*j+3*k+5*m+8*n==20)

                     {

                        temp = pow(1 + 0.0063 * 12, i)

                                                                                    * pow(1 + 0.0066 * 12 * 2, j)

                                                                                    * pow(1 + 0.0069 * 12 * 3, k)

                                                                                    * pow(1 + 0.0075 * 12 * 5, m)

                                                                                    * pow(1 + 0.0084 * 12 * 8, n);

                                                                 if (temp > max)

                            {

                                                                           max = temp;

                                                                           a = i;

                                                                           b = j;

                                                                           c = k;

                                                                           d = m;

                                                                           e = n;

                            }

                    }

                }

            }

        }

    }

 

}

max=max*2000;

printf("For maxinum profit,he should so save his money in a bank:\n");

printf("made fixed deposit for 8 year: %dtimes\n",e);

printf("made fixed deposit for 5 year: %dtimes\n",d);

printf("made fixed deposit for 3 year: %dtimes\n",c);

printf("made fixed deposit for 2 year: %dtimes\n",b);

printf("made fixed deposit for 1 year: %dtimes\n",a);

printf("Total:%.2lf\n",max);

}

int main()

{

    makeMoremoney();

}

*运行结果

For maxinum profit,he should so save his money in a bank:

made fixed deposit for 8 year: 0times

made fixed deposit for 5 year: 4times

made fixed deposit for 3 year: 0times

made fixed deposit for 2 year: 0times

made fixed deposit for 1 year: 0times

Total:8841.01

可见最佳的存款方案为连续四次存5年期。

 

 

*思考题

某单位对职工出售住房,每套为2万元。买房付款的方法是:

一次交清,优惠20%

从第一年开始,每年年初分期付款:

5年交清,优惠15%;

10年交清,优惠10%;

20年交清,没有优惠。

现在有人手中正好有2万元,若假定在今后20年中物价和银行利率均保持不变,问他应当选择哪种付款方式可以使应付的钱最少?

#include<stdio.h>

#include<math.h>

void minPaymoney()

{

    double a,b,c,d,min,cent;

    int flag;

    printf("请输入银行利率(小数形式):");

    scanf("%lf",&cent);

    a=20000*0.8;

    b=20000*0.85*pow(1+cent,5);

    c=20000*0.9*pow(1+cent,10);

    d=20000*pow(1+cent,20);

    min=a;

    flag=1;

    if(a>b)

    {

        min=b;

        flag=2;

    }

    if(min>c)

    {

        min=c;

        flag=3;

    }

    if(min>d)

    {

        min=d;

        flag=4;

    }

    printf("\n");

   switch(flag)

    {

    case 1:

        printf("一次交清,优惠20%");

        break;

    case 2:

        printf("5年交清, 优惠15%");

        break;

    case 3:

        printf("10年交清,优惠10%");

        break;

    case 4:

        printf("20年交清,没有优惠");

        break;

    default :

        printf("error");

        break;

    }

printf(",此付款方式可以使应付的钱最少。应付总额:%lf\n",min);

}

int main()

{

    minPaymoney();

    return 0;

}

posted @ 2017-08-16 21:11  我大概是只废喵  阅读(191)  评论(0编辑  收藏  举报